1 // Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <gtest/gtest.h>
6
7 #include "cras_checksum.h"
8 #include "cras_util.h"
9
10 namespace {
11
12 struct TestCase {
13 const char *input;
14 uint32_t output;
15 };
16
17 static TestCase test_case[] =
18 {
19 /* The answers can be obtained by a command like "echo -n a | cksum" */
20 { "", 4294967295U },
21 { "a", 1220704766U },
22 { "12345678901234567890", 970143720U },
23 };
24
TEST(ChecksumTest,All)25 TEST(ChecksumTest, All) {
26 for (size_t i = 0; i < ARRAY_SIZE(test_case); i++) {
27 const char *input = test_case[i].input;
28 uint32_t output = test_case[i].output;
29 EXPECT_EQ(output, crc32_checksum((unsigned char *)input, strlen(input)));
30 }
31 }
32
33 } // namespace
34
main(int argc,char ** argv)35 int main(int argc, char **argv) {
36 ::testing::InitGoogleTest(&argc, argv);
37 return RUN_ALL_TESTS();
38 }
39