• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /* The answers can be obtained by a command like "echo -n a | cksum" */
19     {"", 4294967295U},
20     {"a", 1220704766U},
21     {"12345678901234567890", 970143720U},
22 };
23 
TEST(ChecksumTest,All)24 TEST(ChecksumTest, All) {
25   for (size_t i = 0; i < ARRAY_SIZE(test_case); i++) {
26     const char* input = test_case[i].input;
27     uint32_t output = test_case[i].output;
28     EXPECT_EQ(output, crc32_checksum((unsigned char*)input, strlen(input)));
29   }
30 }
31 
32 }  //  namespace
33 
main(int argc,char ** argv)34 int main(int argc, char** argv) {
35   ::testing::InitGoogleTest(&argc, argv);
36   return RUN_ALL_TESTS();
37 }
38