int main() {
	// Load data from files
	std::string package1;
	std::ifstream OutputGNSSMovementTrue_DataValidTrue( "testData_GNSSMovementTrue_DataValidTrue.txt" );
	getline( OutputGNSSMovementTrue_DataValidTrue, package1);

	std::string package2;
	std::ifstream OutputGNSSMovementFalse_DataValidTrue("testData_GNSSMovementFalse_DataValidTrue.txt" );
	getline( OutputGNSSMovementFalse_DataValidTrue, package2);

	std::ifstream expectedOutput( "testResultData3.txt" );
	getline( expectedOutput, expected);

	// Start the test

	ap_uint<1> input = 0;
	std::ifstream package4( "testData_CPPMMovementTrue_DataValidTrue.txt" );
	// 18 = CPPM (sync + 2x 8 pulses + sync) +2
	for(int i = 0; i < 20 ; i++)
	{
		// Invert pulse (high to low and low to high)
		input ^= 1;

		std::string temp;
		getline( package4, temp);
		int clocks_to_send = std::atoi(temp.c_str());

		// Send the same bit for a bit-length of clock cycles
		final_test_result += sendCppmPackage(clocks_to_send, input);
	}
	std::cout << most_reliable;

	sendUbxPackage(package1, package2);

	input = 0;
	std::ifstream package5( "testData_CPPMMovementFalse_DataValidTrue.txt" );
	// 18 = CPPM (sync + 2x 8 pulses + sync) +2
	for(int i = 0; i < 20 ; i++)
	{
		// Invert pulse (high to low and low to high)
		input ^= 1;

		std::string temp;
		getline( package5, temp);
		int clocks_to_send = std::atoi(temp.c_str());

		// Send the same bit for a bit-length of clock cycles
		final_test_result += sendCppmPackage(clocks_to_send, input);
	}
	std::cout << most_reliable;

	sendUbxPackage(package1, "");

	// Return the test result
	return final_test_result;
}
Example #2
0
TEST(KURLTest, Encode)
{
    struct EncodeCase {
        const char* input;
        const char* output;
    } encode_cases[] = {
        {"hello, world", "hello%2C%20world"},
        {"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
          "%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F"},
        {"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
          "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F"},
        {" !\"#$%&'()*+,-./", "%20!%22%23%24%25%26%27()*%2B%2C-./"},
        {"0123456789:;<=>?",
          "0123456789%3A%3B%3C%3D%3E%3F"},
        {"@ABCDEFGHIJKLMNO",
          "%40ABCDEFGHIJKLMNO"},
        {"PQRSTUVWXYZ[\\]^_",
          "PQRSTUVWXYZ%5B%5C%5D%5E_"},
        {"`abcdefghijklmno",
          "%60abcdefghijklmno"},
        {"pqrstuvwxyz{|}~\x7f",
          "pqrstuvwxyz%7B%7C%7D~%7F"},
    };

    for (size_t i = 0; i < arraysize(encode_cases); i++) {
        String input(encode_cases[i].input);
        String expectedOutput(encode_cases[i].output);
        String output = encodeWithURLEscapeSequences(input);
        EXPECT_EQ(expectedOutput, output);
    }

    // Our encode escapes NULLs for safety, so we need to check that too.
    String input("\x00\x01", 2);
    String reference("%00%01");

    String output = encodeWithURLEscapeSequences(input);
    EXPECT_EQ(reference, output);

    // Also test that it gets converted to UTF-8 properly.
    UChar wideInputHelper[3] = { 0x4f60, 0x597d, 0 };
    String wideInput(reinterpret_cast<const ::UChar*>(wideInputHelper), 2);
    String wideReference("%E4%BD%A0%E5%A5%BD");
    String wideOutput = encodeWithURLEscapeSequences(wideInput);
    EXPECT_EQ(wideReference, wideOutput);

    // Encoding should not NFC-normalize the string.
    // Contain a combining character ('e' + COMBINING OGONEK).
    String combining(String::fromUTF8("\x65\xCC\xA8"));
    EXPECT_EQ(encodeWithURLEscapeSequences(combining), "e%CC%A8");
    // Contain a precomposed character corresponding to |combining|.
    String precomposed(String::fromUTF8("\xC4\x99"));
    EXPECT_EQ(encodeWithURLEscapeSequences(precomposed), "%C4%99");
}
Example #3
0
   void testMultipleInput()
      {
         // Table of test cases.
         struct test {
            int          numInputs;
            const char*  inputs[6];
            const char*  output;
         };
         struct test tests[] = {
            // Varying length strings of 0's.
            // 0
            { 2, { "", "" },
              "d41d8cd98f00b204e9800998ecf8427e" },
            // 1
            { 2, { "0", "" },
              "cfcd208495d565ef66e7dff9f98764da" },
            // 2
            { 2, { "0", "0" },
              "b4b147bc522828731f1a016bfa72c073" },
            // 3
            { 3, { "00", "0", "0" },
              "4a7d1ed414474e4033ac29ccb8653d9b" },
            // 4
            { 2, { "000", "00000" },
              "dd4b21e9ef71e1291183a46b913ae6f2" },
            // 5
            { 1, { "0000000000000000" },
              "1e4a1b03d1b6cd8a174a826f76e009f4" },
            // 6
            { 3, { "", "0000000", "0000000000000000000000000" },
              "cd9e459ea708a948d5c2f5a6ca8838cf" },
            // 7
            { 2, { "000000000000000", "0000000000000000000000000000000000000000000000000" },
              "10eab6008d5642cf42abd2aa41f847cb" },
            // 8
            { 1, { "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" },
              "aa70aaf67b3bab5029b76cee92e18afe" },
            // Varying length strings of the ASCII characters.
            // 8
            { 2, { " ", "" },
              "7215ee9c7d9dc229d2921a40e899ec5f" },
            // 9
            { 2, { " ", "!" },
              "220c1c252883eadad5590fc9e6a61739" },
            // 10
            { 2, { " !\"", "#" },
              "1a8bed44f8555d8318157f1e649a99b5" },
            // 11
            { 2, { " !\"#", "$%&'" },
              "04281adcae556d29c613104883b36133" },
            // 12
            { 2, { " ", "!\"#$%&'()*+,-./" },
              "35ba6d08f0e34c15b9d0b09998960eb6" },
            // 13
            { 2, { " !\"#$%&'()*+,-.", "/0123456789:;<=>?" },
              "bf61e899560fabde2f6d76f405a6eb70" },
            // 14
            { 2, { " !\"#$%&'()*+,-./0123456789:;<=>?@A", "BCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" },
              "c654a1965b312ddee3bd884e044a7658" },
            // 15
            { 2, { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDE", "FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ " },
              "6c16dd02a16a44568a8fd4b9bf2fdddd" },
            // Strings of length 65:  Since MD5 processes chars in blocks
            // of 64, this tests behavior across block boundaries.
            // 16
            { 2, { "00000000000000000000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000000000000000000" },
              "c7f6509e1fde3ebc0c246b98ca17ca53" },
            // 17
            { 1, { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" },
              "bf35d3d5ee617924bbaabfef05b78d30" },
            // A couple of more normal strings.
            // 18
            { 5, { "john.salesman", ":", "sales/example.com", ":", "5+5=10" },
              "91ffcb1f8353fe113ccf7169ee27402e" },
            // 19
            { 1, { "GET:/private/prices.html" },
              "254bd53db6966fa1387fa1973bb5e53c" }
         };

         UtlString prefix("prefix/");
         bool allPassed=true;
         for (unsigned int testcase = 0;
              testcase < sizeof(tests) / sizeof(struct test);
              testcase++
              )
         {
            NetMd5Codec md5;
            NetMd5Codec md5sig;
            UtlString concatenatedInput;
            
            for (int input = 0; input < tests[testcase].numInputs; input++)
            {
               concatenatedInput.append(tests[testcase].inputs[input]);
               
               md5.hash(tests[testcase].inputs[input],
                        strlen(tests[testcase].inputs[input])
                        );
               md5sig.hash(tests[testcase].inputs[input],
                           strlen(tests[testcase].inputs[input])
                           );
            }
            UtlString actualOutputSegmented(prefix);
            md5.appendHashValue(actualOutputSegmented);

            UtlString prefixedOutputConcatenated(prefix);
            UtlString actualOutputConcatenated;
            NetMd5Codec::encode(concatenatedInput.data(), actualOutputConcatenated);
            prefixedOutputConcatenated.append(actualOutputConcatenated);
            
            if (actualOutputSegmented.compareTo(prefixedOutputConcatenated) != 0)
            {
               allPassed=false;
               OsSysLog::add(FAC_SIP, PRI_ERR,
                             "md5 multiple input test %d, segmented: %s\n  concatenated: %s",
                             testcase, actualOutputSegmented.data(), prefixedOutputConcatenated.data());
            }
            
            UtlString sigOutputSegmented(prefix);
            md5sig.appendBase64Sig(sigOutputSegmented);

            UtlString sigPrefixedOutputConcatenated(prefix);
            UtlString sigOutputConcatenated;
            NetMd5Codec::encodeBase64Sig(concatenatedInput.data(), sigOutputConcatenated);
            sigPrefixedOutputConcatenated.append(sigOutputConcatenated);
            
            if (sigOutputSegmented.compareTo(sigPrefixedOutputConcatenated) != 0)
            {
               allPassed=false;
               OsSysLog::add(FAC_SIP, PRI_ERR,
                             "md5 multiple input test %d, segmented: %s\n  concatenated: %s",
                             testcase, sigOutputSegmented.data(), sigPrefixedOutputConcatenated.data());
            }

            UtlString expectedOutput(prefix);
            expectedOutput.append(tests[testcase].output);
            
            if (actualOutputSegmented.compareTo(expectedOutput) != 0)
            {
               allPassed=false;
               OsSysLog::add(FAC_SIP, PRI_ERR,
                             "md5 multiple input test %d, expected: %s\n  received: %s",
                             testcase, actualOutputSegmented.data(), expectedOutput.data());
            }
         }
         
         CPPUNIT_ASSERT(allPassed);

         
      }
Example #4
0
   void testMultipleInput()
      {
         // Table of test cases.
         struct test {
            int          numInputs;
            const char*  inputs[6];
            const char*  output;
         };
         struct test tests[] = {
            // Varying length strings of 0's.
            { 2, { "", "" },
              "d41d8cd98f00b204e9800998ecf8427e" },
            { 2, { "0", "" },
              "cfcd208495d565ef66e7dff9f98764da" },
            { 2, { "0", "0" },
              "b4b147bc522828731f1a016bfa72c073" },
            { 3, { "00", "0", "0" },
              "4a7d1ed414474e4033ac29ccb8653d9b" },
            { 2, { "000", "00000" },
              "dd4b21e9ef71e1291183a46b913ae6f2" },
            { 1, { "0000000000000000" },
              "1e4a1b03d1b6cd8a174a826f76e009f4" },
            { 3, { "", "0000000", "0000000000000000000000000" },
              "cd9e459ea708a948d5c2f5a6ca8838cf" },
            { 2, { "000000000000000", "0000000000000000000000000000000000000000000000000" },
              "10eab6008d5642cf42abd2aa41f847cb" },
            { 1, { "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" },
              "aa70aaf67b3bab5029b76cee92e18afe" },
            // Varying length strings of the ASCII characters.
            { 2, { " ", "" },
              "7215ee9c7d9dc229d2921a40e899ec5f" },
            { 2, { " ", "!" },
              "220c1c252883eadad5590fc9e6a61739" },
            { 2, { " !\"", "#" },
              "1a8bed44f8555d8318157f1e649a99b5" },
            { 2, { " !\"#", "$%&'" },
              "04281adcae556d29c613104883b36133" },
            { 2, { " ", "!\"#$%&'()*+,-./" },
              "35ba6d08f0e34c15b9d0b09998960eb6" },
            { 2, { " !\"#$%&'()*+,-.", "/0123456789:;<=>?" },
              "bf61e899560fabde2f6d76f405a6eb70" },
            { 2, { " !\"#$%&'()*+,-./0123456789:;<=>?@A", "BCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" },
              "c654a1965b312ddee3bd884e044a7658" },
            { 2, { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDE", "FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ " },
              "6c16dd02a16a44568a8fd4b9bf2fdddd" },
            // Strings of length 65:  Since MD5 processes chars in blocks
            // of 64, this tests behavior across block boundaries.
            { 2, { "00000000000000000000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000000000000000000" },
              "c7f6509e1fde3ebc0c246b98ca17ca53" },
            { 1, { " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" },
              "bf35d3d5ee617924bbaabfef05b78d30" },
            // A couple of more normal strings.
            { 5, { "john.salesman", ":", "sales/example.com", ":", "5+5=10" },
              "91ffcb1f8353fe113ccf7169ee27402e" },
            { 1, { "GET:/private/prices.html" },
              "254bd53db6966fa1387fa1973bb5e53c" }
         };

         UtlString prefix("prefix/");
         for (unsigned int testcase = 0;
              testcase < sizeof(tests) / sizeof(struct test);
              testcase++
              )
         {
            NetMd5Codec md5;

            for (int input = 0; input < tests[testcase].numInputs; input++)
            {
               md5.hash(tests[testcase].inputs[input],
                        strlen(tests[testcase].inputs[input])
                        );
            }
            UtlString actualOutput(prefix);
            md5.appendHashValue(actualOutput);

            UtlString expectedOutput(prefix);
            expectedOutput.append(tests[testcase].output);
            
            char msg[1024];
            sprintf(msg, "test %d did not match",
                    testcase
                    );
            CPPUNIT_ASSERT_MESSAGE(msg, expectedOutput.compareTo(actualOutput) == 0);
         }
      }