Projekt

Allgemein

Profil

Feature #446 » test_crc32.cpp

Maximilian Seesslen, 28.11.2023 19:12

 
1
//----------------------------------------------------------------------------
2
///
3
/// \file   main.cpp
4
///
5
/// \brief  main file for pinmux
6
///
7
/// \date   20220619
8
/// \author Maximilian Seesslen <mes@seesslen.net>
9
///
10
//----------------------------------------------------------------------------
11

    
12

    
13
//---Documentation------------------------------------------------------------
14

    
15

    
16
//---Includes -----------------------------------------------------------------
17

    
18

    
19
//---General--------------------------
20

    
21

    
22
#if defined ( CATCH2 )
23
   #include <catch2/catch.hpp>
24
#elif defined ( CATCH )
25
   #include <catch/catch.hpp>
26
#else
27
   #error "Either 'catch' or 'catch2' has to be installed"
28
#endif
29

    
30
#include <lepto/crc32.h>
31
#include <string.h>        // strlen
32

    
33

    
34
//--- Own ----------------------------
35

    
36
#define TEST_ALL
37
#define STOP_ON_FAIL
38

    
39
//---Implementation------------------------------------------------------------
40

    
41

    
42
TEST_CASE( "CRC32", "[default]" )
43
{
44
   SECTION( "CRC32" )
45
   {
46
      char *data="Hello World!";
47
      char *data1="Hello ";
48
      char *data2="World!";
49

    
50
      {
51
         crc32_t crc;
52
         crc=crc32Init();
53
         crc=crc32Update(crc, data1, strlen(data1));
54
         crc=crc32Update(crc, data2, strlen(data2));
55
         crc=crc32Finalize(crc);
56

    
57
         REQUIRE ( crc == 0x1C291CA3 );
58
      }
59

    
60
      {
61
         crc32_t crc;
62
         crc=crc32MpegInit();
63
         crc=crc32MpegUpdate(crc, data1, strlen(data1));
64
         crc=crc32MpegUpdate(crc, data2, strlen(data2));
65
         crc=crc32MpegFinalize(crc);
66

    
67
         REQUIRE ( crc == 0x94E58351 );
68
      }
69

    
70
      {
71
         crc32_t crc=0;
72
         crc = calcCrc32( data, strlen(data) );
73

    
74
         REQUIRE ( crc ==  0x1C291CA3 );
75
      }
76

    
77
   }
78
}
79

    
80

    
81
//---fin-----------------------------------------------------------------------
(1-1/3)