Пример #1
0
TEST(String, Split)
{
    char **argv, *str;
    int argc;

    POINTERS_EQUAL(NULL, string_split (NULL, NULL, 0, 0, NULL));
    POINTERS_EQUAL(NULL, string_split (NULL, "", 0, 0, NULL));
    POINTERS_EQUAL(NULL, string_split ("", NULL, 0, 0, NULL));
    POINTERS_EQUAL(NULL, string_split ("", "", 0, 0, NULL));

    argc = 1;
    POINTERS_EQUAL(NULL, string_split (NULL, NULL, 0, 0, &argc));
    LONGS_EQUAL(0, argc);
    argc = 1;
    POINTERS_EQUAL(NULL, string_split (NULL, "", 0, 0, &argc));
    LONGS_EQUAL(0, argc);
    argc = 1;
    POINTERS_EQUAL(NULL, string_split ("", NULL, 0, 0, &argc));
    LONGS_EQUAL(0, argc);
    argc = 1;
    POINTERS_EQUAL(NULL, string_split ("", "", 0, 0, &argc));
    LONGS_EQUAL(0, argc);

    /* free split with NULL */
    string_free_split (NULL);
    string_free_split_shared (NULL);
    string_free_split_command (NULL);

    /* standard split */
    argv = string_split (" abc de  fghi ", " ", 0, 0, &argc);
    LONGS_EQUAL(3, argc);
    STRCMP_EQUAL("abc", argv[0]);
    STRCMP_EQUAL("de", argv[1]);
    STRCMP_EQUAL("fghi", argv[2]);
    POINTERS_EQUAL(NULL, argv[3]);
    string_free_split (argv);

    /* max 2 items */
    argv = string_split (" abc de  fghi ", " ", 0, 2, &argc);
    LONGS_EQUAL(2, argc);
    STRCMP_EQUAL("abc", argv[0]);
    STRCMP_EQUAL("de", argv[1]);
    POINTERS_EQUAL(NULL, argv[2]);
    string_free_split (argv);

    /* keep eol */
    argv = string_split (" abc de  fghi ", " ", 1, 0, &argc);
    LONGS_EQUAL(3, argc);
    STRCMP_EQUAL("abc de  fghi", argv[0]);
    STRCMP_EQUAL("de  fghi", argv[1]);
    STRCMP_EQUAL("fghi", argv[2]);
    POINTERS_EQUAL(NULL, argv[3]);
    string_free_split (argv);

    /* keep eol and max 2 items */
    argv = string_split (" abc de  fghi ", " ", 1, 2, &argc);
    LONGS_EQUAL(2, argc);
    STRCMP_EQUAL("abc de  fghi", argv[0]);
    STRCMP_EQUAL("de  fghi", argv[1]);
    POINTERS_EQUAL(NULL, argv[2]);
    string_free_split (argv);

    /* split with shared strings */
    argv = string_split_shared (" abc de  abc ", " ", 0, 0, &argc);
    LONGS_EQUAL(3, argc);
    STRCMP_EQUAL("abc", argv[0]);
    STRCMP_EQUAL("de", argv[1]);
    STRCMP_EQUAL("abc", argv[2]);
    POINTERS_EQUAL(NULL, argv[3]);
    /* same content == same pointer for shared strings */
    POINTERS_EQUAL(argv[0], argv[2]);
    string_free_split_shared (argv);

    /* build string with split string */
    str = string_build_with_split_string (NULL, NULL);
    POINTERS_EQUAL(NULL, str);
    argv = string_split (" abc de  fghi ", " ", 0, 0, &argc);
    str = string_build_with_split_string ((const char **)argv, NULL);
    STRCMP_EQUAL("abcdefghi", str);
    free (str);
    str = string_build_with_split_string ((const char **)argv, "");
    STRCMP_EQUAL("abcdefghi", str);
    free (str);
    str = string_build_with_split_string ((const char **)argv, ";;");
    STRCMP_EQUAL("abc;;de;;fghi", str);
    free (str);
    string_free_split (argv);

    /* split command */
    POINTERS_EQUAL(NULL, string_split_command (NULL, ';'));
    POINTERS_EQUAL(NULL, string_split_command ("", ';'));
    argv = string_split_command ("abc;de;fghi", ';');
    LONGS_EQUAL(3, argc);
    STRCMP_EQUAL("abc", argv[0]);
    STRCMP_EQUAL("de", argv[1]);
    STRCMP_EQUAL("fghi", argv[2]);
    POINTERS_EQUAL(NULL, argv[3]);
    string_free_split_command (argv);
}
Пример #2
0
TEST(LightControllerSpy,RememberTheLastlightIdControlled)
{
  LightController_On(10);
  LONGS_EQUAL(10,LightControllerSpy_GetLastId());
  LONGS_EQUAL(LIGHT_ON,LightControllerSpy_GetLastState());
}
Пример #3
0
 void validateExceptionCode(int expectedExceptionCode)
 {
     m_expectedException = expectedExceptionCode;
     LONGS_EQUAL ( expectedExceptionCode, getExceptionCode() );
 }
Пример #4
0
TEST(problem62, get_smallest_3_cube_permutation)
{
	LONGS_EQUAL(345,CubePermutation().get_smallest_n_cube_permutations(3)->getRoot(0));
}
Пример #5
0
TEST(problem62, get_add_to_permutation_hash)
{
	CubePermutation cp;
	LONGS_EQUAL(1, cp.add_to_cube_permutation_hash(1));
	LONGS_EQUAL(1, cp.add_to_cube_permutation_hash(2));
}
Пример #6
0
TEST(MockSupport_c, returnStringValue)
{
    mock_c()->expectOneCall("boo")->andReturnStringValue("hello world");
    STRCMP_EQUAL("hello world", mock_c()->actualCall("boo")->returnValue().value.stringValue);
    LONGS_EQUAL(MOCKVALUETYPE_STRING, mock_c()->returnValue().type);
}
Пример #7
0
TEST(MockSupport_c, MockSupportSetIntData)
{
    mock_c()->setIntData("integer", 10);
    LONGS_EQUAL(10, mock_c()->getData("integer").value.intValue);
}
Пример #8
0
TEST(spiral, second_coner){
	LONGS_EQUAL(7, get_diagnal_of_spiral(1, 1));
}
Пример #9
0
TEST(spiral, third_coner){
	LONGS_EQUAL(5, get_diagnal_of_spiral(1, 2));
}
TEST(CircularBuffer, Capacity)
{
	CircularBuffer buffer(2);
	LONGS_EQUAL(2, buffer.Capacity());
}
Пример #11
0
TEST(spiral, first_coner){
	LONGS_EQUAL(9, get_diagnal_of_spiral(1, 0));
}
TEST(CircularBuffer, GetPutOneValue)
{
	buffer->Put(4567);
	LONGS_EQUAL(4567, buffer->Get());
}
TEST(CircularBuffer, GetFromEmpty)
{
	LONGS_EQUAL(-1, buffer->Get());
	CHECK(buffer->IsEmpty());
}
Пример #14
0
TEST(String, BaseN)
{
    char str[1024];
    const char *str_abc = "abc";
    const char *str_abc_base64 = "YWJj";
    const char *str_base64[][2] =
        { { "", "" },
          { "A", "QQ==" },
          { "B", "Qg==" },
          { "C", "Qw==" },
          { "D", "RA==" },
          { "abc", "YWJj" },
          { "This is a test.", "VGhpcyBpcyBhIHRlc3Qu" },
          { "This is a test..", "VGhpcyBpcyBhIHRlc3QuLg==" },
          { "This is a test...", "VGhpcyBpcyBhIHRlc3QuLi4=" },
          { "This is a test....", "VGhpcyBpcyBhIHRlc3QuLi4u" },
          { "This is a long long long sentence here...",
            "VGhpcyBpcyBhIGxvbmcgbG9uZyBsb25nIHNlbnRlbmNlIGhlcmUuLi4=" },
          { "Another example for base64",
            "QW5vdGhlciBleGFtcGxlIGZvciBiYXNlNjQ=" },
          { "Another example for base64.",
            "QW5vdGhlciBleGFtcGxlIGZvciBiYXNlNjQu" },
          { "Another example for base64..",
            "QW5vdGhlciBleGFtcGxlIGZvciBiYXNlNjQuLg==" },
          { "Another example for base64...",
            "QW5vdGhlciBleGFtcGxlIGZvciBiYXNlNjQuLi4=" },
          { NULL, NULL } };
    int i, length;

    /* string_encode_base16 */
    string_encode_base16 (NULL, 0, NULL);
    string_encode_base16 (NULL, 0, str);
    string_encode_base16 ("", 0, NULL);
    str[0] = 0xAA;
    string_encode_base16 ("", -1, str);
    BYTES_EQUAL(0x0, str[0]);
    str[0] = 0xAA;
    string_encode_base16 ("", 0, str);
    BYTES_EQUAL(0x0, str[0]);
    string_encode_base16 ("abc", 3, str);
    STRCMP_EQUAL("616263", str);

    /* string_decode_base16 */
    LONGS_EQUAL(0, string_decode_base16 (NULL, NULL));
    LONGS_EQUAL(0, string_decode_base16 (NULL, str));
    LONGS_EQUAL(0, string_decode_base16 ("", NULL));
    LONGS_EQUAL(0, string_decode_base16 ("", str));
    LONGS_EQUAL(3, string_decode_base16 ("616263", str));
    STRCMP_EQUAL("abc", str);

    /* string_encode_base64 */
    string_encode_base64 (NULL, 0, NULL);
    string_encode_base64 (NULL, 0, str);
    string_encode_base64 ("", 0, NULL);
    str[0] = 0xAA;
    string_encode_base64 ("", -1, str);
    BYTES_EQUAL(0x0, str[0]);
    str[0] = 0xAA;
    string_encode_base64 ("", 0, str);
    BYTES_EQUAL(0x0, str[0]);
    for (i = 0; str_base64[i][0]; i++)
    {
        string_encode_base64 (str_base64[i][0], strlen (str_base64[i][0]),
                              str);
        STRCMP_EQUAL(str_base64[i][1], str);
    }

    /* string_decode_base64 */
    LONGS_EQUAL(0, string_decode_base64 (NULL, NULL));
    LONGS_EQUAL(0, string_decode_base64 (NULL, str));
    LONGS_EQUAL(0, string_decode_base64 ("", NULL));
    LONGS_EQUAL(0, string_decode_base64 ("", str));
    for (i = 0; str_base64[i][0]; i++)
    {
        length = string_decode_base64 (str_base64[i][1], str);
        STRCMP_EQUAL(str_base64[i][0], str);
        LONGS_EQUAL(strlen (str_base64[i][0]), length);
    }
}
TEST(IQmath_Multiplication, IQ30mpyNegative)
{
    LONGS_EQUAL(_IQ30(0.75), _IQ30mpy(_IQ30(-1.5), _IQ30(-0.5))) ;
    LONGS_EQUAL(_IQ30(-0.999999998), _IQ30mpy(_IQ30(-0.666666666), _IQ30(1.5))) ;
}
Пример #16
0
TEST(spiral, fourth_coner){
	LONGS_EQUAL(3, get_diagnal_of_spiral(1, 3));
}
Пример #17
0
TEST(MockSupport_c, returnDoubleValue)
{
    mock_c()->expectOneCall("boo")->andReturnDoubleValue(1.0);
    DOUBLES_EQUAL(1.0, mock_c()->actualCall("boo")->returnValue().value.doubleValue, 0.005);
    LONGS_EQUAL(MOCKVALUETYPE_DOUBLE, mock_c()->returnValue().type);
}
Пример #18
0
TEST(spiral, next_circle1){
	LONGS_EQUAL(25, get_diagnal_of_spiral(2, 0));
}
Пример #19
0
TEST(MockSupport_c, returnConstPointerValue)
{
    mock_c()->expectOneCall("boo")->andReturnConstPointerValue((const void*) 10);
    POINTERS_EQUAL((const void*) 10, mock_c()->actualCall("boo")->returnValue().value.constPointerValue);
    LONGS_EQUAL(MOCKVALUETYPE_CONST_POINTER, mock_c()->returnValue().type);
}
Пример #20
0
TEST(spiral, next_circle2){
	LONGS_EQUAL(21, get_diagnal_of_spiral(2, 1));
}
Пример #21
0
TEST(problem62, get_smallest_two_cube_permutation)
{
	LONGS_EQUAL(5,CubePermutation().get_smallest_n_cube_permutations(2)->getRoot(0));
	LONGS_EQUAL(8,CubePermutation().get_smallest_n_cube_permutations(2)->getRoot(1));
}
Пример #22
0
TEST(spiral, next_circle3){
	LONGS_EQUAL(17, get_diagnal_of_spiral(2, 2));
}
Пример #23
0
TEST(problem62, get_smallest_5_cube_permutation)
{
	LONGS_EQUAL(5027,CubePermutation().get_smallest_n_cube_permutations(5)->getRoot(0));
}
Пример #24
0
TEST(spiral, next_circle4){
	LONGS_EQUAL(13, get_diagnal_of_spiral(2, 3));
}
Пример #25
0
TEST(problem62, get_smallest_one_cube_permutation)
{
	LONGS_EQUAL(1,CubePermutation().get_smallest_n_cube_permutations(1)->getRoot(0));
}
Пример #26
0
TEST(spiral, next_next){
	LONGS_EQUAL(49, get_diagnal_of_spiral(3, 0));
	LONGS_EQUAL(43, get_diagnal_of_spiral(3, 1));
}
Пример #27
0
 void teardown()
 {
     LONGS_EQUAL ( m_expectedException, getExceptionCode() );
     clearExceptionCode();
     platformMock_Uninit();
 }
TEST(IQmath_Multiplication, IQ1mpyNegative)
{
    LONGS_EQUAL(_IQ1(-3.0), _IQ1mpy(_IQ1(2.0), _IQ1(-1.5))) ;
    LONGS_EQUAL(_IQ1(-1073741823), _IQ1mpy(_IQ1(2.0), _IQ1(-536870911.5))) ;
}
Пример #29
0
 void validateExceptionThrown(int expectedExceptionCode)
 {
     LONGS_EQUAL(expectedExceptionCode, getExceptionCode());
     clearExceptionCode();
 }
Пример #30
0
TEST(String, Regex)
{
    int flags, rc;
    const char *ptr;
    regex_t regex;

    string_regex_flags (NULL, 0, NULL);
    string_regex_flags ("", 0, NULL);

    string_regex_flags (NULL, 0, &flags);
    LONGS_EQUAL(0, flags);
    string_regex_flags ("", 0, &flags);
    LONGS_EQUAL(0, flags);
    string_regex_flags (NULL, REG_EXTENDED, &flags);
    LONGS_EQUAL(REG_EXTENDED, flags);
    string_regex_flags ("", REG_EXTENDED, &flags);
    LONGS_EQUAL(REG_EXTENDED, flags);

    ptr = string_regex_flags ("test", REG_EXTENDED, &flags);
    LONGS_EQUAL(REG_EXTENDED, flags);
    STRCMP_EQUAL("test", ptr);

    string_regex_flags ("(?e)test", 0, &flags);
    LONGS_EQUAL(REG_EXTENDED, flags);
    STRCMP_EQUAL("test", ptr);

    string_regex_flags ("(?ei)test", 0, &flags);
    LONGS_EQUAL(REG_EXTENDED | REG_ICASE, flags);
    STRCMP_EQUAL("test", ptr);

    string_regex_flags ("(?eins)test", 0, &flags);
    LONGS_EQUAL(REG_EXTENDED | REG_ICASE | REG_NEWLINE | REG_NOSUB, flags);
    STRCMP_EQUAL("test", ptr);

    string_regex_flags ("(?ins)test", REG_EXTENDED, &flags);
    LONGS_EQUAL(REG_EXTENDED | REG_ICASE | REG_NEWLINE | REG_NOSUB, flags);
    STRCMP_EQUAL("test", ptr);

    string_regex_flags ("(?ins-e)test", REG_EXTENDED, &flags);
    LONGS_EQUAL(REG_ICASE | REG_NEWLINE | REG_NOSUB, flags);
    STRCMP_EQUAL("test", ptr);

    /* compile regular expression */
    LONGS_EQUAL(-1, string_regcomp (&regex, NULL, 0));
    LONGS_EQUAL(0, string_regcomp (&regex, "", 0));
    regfree (&regex);
    LONGS_EQUAL(0, string_regcomp (&regex, "test", 0));
    regfree (&regex);
    LONGS_EQUAL(0, string_regcomp (&regex, "test", REG_EXTENDED));
    regfree (&regex);
    LONGS_EQUAL(0, string_regcomp (&regex, "(?ins)test", REG_EXTENDED));
    regfree (&regex);
}