summaryrefslogtreecommitdiff
path: root/cras/src/tests/checksum_unittest.cc
blob: 4d54b2c209a6b6d16528ee6cd581d448cd879e72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <gtest/gtest.h>

#include "cras_checksum.h"
#include "cras_util.h"

namespace {

struct TestCase {
  const char* input;
  uint32_t output;
};

static TestCase test_case[] = {
    /* The answers can be obtained by a command like "echo -n a | cksum" */
    {"", 4294967295U},
    {"a", 1220704766U},
    {"12345678901234567890", 970143720U},
};

TEST(ChecksumTest, All) {
  for (size_t i = 0; i < ARRAY_SIZE(test_case); i++) {
    const char* input = test_case[i].input;
    uint32_t output = test_case[i].output;
    EXPECT_EQ(output, crc32_checksum((unsigned char*)input, strlen(input)));
  }
}

}  //  namespace

int main(int argc, char** argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}