Exemple #1
0
TEST(String, SplitShell)
{
    char **argv;
    int argc;

    POINTERS_EQUAL(NULL, string_split_shell (NULL, NULL));

    /* test with an empty string */
    argc = -1;
    argv = string_split_shell ("", &argc);
    LONGS_EQUAL(0, argc);
    CHECK(argv);
    POINTERS_EQUAL(NULL, argv[0]);
    string_free_split (argv);

    /* test with a real string (command + arguments) */
    argv = string_split_shell ("/path/to/bin arg1 \"arg2 here\" 'arg3 here'",
                               &argc);
    LONGS_EQUAL(4, argc);
    CHECK(argv);
    STRCMP_EQUAL("/path/to/bin", argv[0]);
    STRCMP_EQUAL("arg1", argv[1]);
    STRCMP_EQUAL("arg2 here", argv[2]);
    STRCMP_EQUAL("arg3 here", argv[3]);
    POINTERS_EQUAL(NULL, argv[4]);
    string_free_split (argv);

    /* free split with NULL */
    string_free_split_shared (NULL);
}
Exemple #2
0
TEST(RandomClass, CreateXOrShiftObject)
{
	Random* pRandom;
	uint32_t nResult = 0;
	pRandom = random_new(setXorShiftSeed, nextXorShiftUInt32);
	POINTERS_EQUAL(setXorShiftSeed, pRandom->setSeed);
	POINTERS_EQUAL(nextXorShiftUInt32, pRandom->getNextUInt32);
}
TEST(TestMemoryAllocatorTest, SetCurrentMallocAllocator)
{
    allocator = new TestMemoryAllocator("malloc_allocator");
    setCurrentMallocAllocator(allocator);
    POINTERS_EQUAL(allocator, getCurrentMallocAllocator());
    setCurrentMallocAllocatorToDefault();
    POINTERS_EQUAL(defaultMallocAllocator(), getCurrentMallocAllocator());
}
TEST(MockSupport_c, whenReturnValueIsGivenReturnConstPointerValueOrDefaultShouldIgnoreTheDefault)
{
    const void* defaultValue = (void*) 10;
    const void* expectedValue = (void*) 27;
    mock_c()->expectOneCall("foo")->andReturnConstPointerValue(expectedValue);
    POINTERS_EQUAL(expectedValue, mock_c()->actualCall("foo")->returnConstPointerValueOrDefault(defaultValue));
    POINTERS_EQUAL(expectedValue, mock_c()->returnConstPointerValueOrDefault(defaultValue));
}
TEST(TestMemoryAllocatorTest, SetCurrentNewArrayAllocator)
{
    allocator = new TestMemoryAllocator("new array allocator for test");
    setCurrentNewArrayAllocator(allocator);
    POINTERS_EQUAL(allocator, getCurrentNewArrayAllocator());
    setCurrentNewArrayAllocatorToDefault();
    POINTERS_EQUAL(defaultNewArrayAllocator(), getCurrentNewArrayAllocator());
}
Exemple #6
0
TEST(HttpdSingletonTestGroup, Instantiate)
{
   HttpdSingleton   *Httpd = HttpdSingleton::Instantiate();

   CHECK(Httpd != NULL);
   POINTERS_EQUAL(Httpd, HttpdSingleton::Instantiate());
   POINTERS_EQUAL(Httpd, HttpdSingleton::Instantiate());
   HttpdSingleton::Instantiate(false);
};
Exemple #7
0
TEST(HttpdSingletonTestGroup, StartStop)
{
   CHECK(HttpdSingleton::Instantiate() != NULL);
   POINTERS_EQUAL(NULL, HttpdSingleton::Instantiate(false));
   CHECK(HttpdSingleton::Instantiate() != NULL);
   POINTERS_EQUAL(NULL, HttpdSingleton::Instantiate(false));
   POINTERS_EQUAL(NULL, HttpdSingleton::Instantiate(false));
   CHECK(HttpdSingleton::Instantiate() != NULL);
   POINTERS_EQUAL(NULL, HttpdSingleton::Instantiate(false));
};
Exemple #8
0
TEST(String, Strip)
{
    POINTERS_EQUAL(NULL, string_strip (NULL, 1, 1, NULL));
    POINTERS_EQUAL(NULL, string_strip (NULL, 1, 1, ".;"));
    STRCMP_EQUAL("test", string_strip ("test", 1, 1, NULL));
    STRCMP_EQUAL("test", string_strip ("test", 1, 1, ".;"));
    STRCMP_EQUAL(".-test.-", string_strip (".-test.-", 0, 0, ".-"));
    STRCMP_EQUAL("test", string_strip (".-test.-", 1, 1, ".-"));
    STRCMP_EQUAL("test.-", string_strip (".-test.-", 1, 0, ".-"));
    STRCMP_EQUAL(".-test", string_strip (".-test.-", 0, 1, ".-"));
}
TEST(MockNamedValueComparatorRepository, installMultipleComparator)
{
	TypeForTestingExpectedFunctionCallComparator comparator1, comparator2, comparator3;
	MockNamedValueComparatorRepository repository;
	repository.installComparator("type1", comparator1);
	repository.installComparator("type2", comparator2);
	repository.installComparator("type3", comparator3);
	POINTERS_EQUAL(&comparator3, repository.getComparatorForType("type3"));
	POINTERS_EQUAL(&comparator2, repository.getComparatorForType("type2"));
	POINTERS_EQUAL(&comparator1, repository.getComparatorForType("type1"));
}
TEST(CircularBuffer, shouldHaveGetAndIncrementFunction) {
	
	uint16_t *buf = (uint16_t*) malloc(sizeof(uint16_t)*4);
	CircularBuffer cb = CircularBuffer_New(buf, 4, 2);
 
	POINTERS_EQUAL( CircularBuffer_GetNextBuffer( cb ), buf );
	POINTERS_EQUAL( CircularBuffer_GetNextBuffer( cb ), buf+2 );
	free( buf );
	free( cb );
	
}
TEST(CircularBuffer, shouldSupportLargeSplit) {
	
	uint16_t *buf = (uint16_t*) malloc(sizeof(uint16_t)*16);
	CircularBuffer cb = CircularBuffer_New( buf, 16, 4);
	
	POINTERS_EQUAL( CircularBuffer_GetNextBuffer( cb ), buf );
	POINTERS_EQUAL( CircularBuffer_GetNextBuffer( cb ), buf+4 );
	POINTERS_EQUAL( CircularBuffer_GetNextBuffer( cb ), buf+8 );
	POINTERS_EQUAL( CircularBuffer_GetNextBuffer( cb ), buf+12 );
	POINTERS_EQUAL( CircularBuffer_GetNextBuffer( cb ), buf );

	free( buf );
	free( cb );	
}
Exemple #12
0
TEST(String, RemoveQuotes)
{
    POINTERS_EQUAL(NULL, string_remove_quotes (NULL, NULL));
    POINTERS_EQUAL(NULL, string_remove_quotes (NULL, "abc"));
    POINTERS_EQUAL(NULL, string_remove_quotes ("abc", NULL));
    STRCMP_EQUAL("", string_remove_quotes("", ""));
    STRCMP_EQUAL("", string_remove_quotes("", "\"'"));
    STRCMP_EQUAL("abc", string_remove_quotes("abc", "\"'"));
    STRCMP_EQUAL(" abc ", string_remove_quotes(" abc ", "\"'"));
    STRCMP_EQUAL("abc", string_remove_quotes("'abc'", "\"'"));
    STRCMP_EQUAL("abc", string_remove_quotes(" 'abc' ", "\"'"));
    STRCMP_EQUAL("'abc'", string_remove_quotes("\"'abc'\"", "\"'"));
    STRCMP_EQUAL("'abc'", string_remove_quotes(" \"'abc'\" ", "\"'"));
    STRCMP_EQUAL("'a'b'c'", string_remove_quotes("\"'a'b'c'\"", "\"'"));
    STRCMP_EQUAL("'a'b'c'", string_remove_quotes(" \"'a'b'c'\" ", "\"'"));
}
Exemple #13
0
static int functionThatReturnsAValue()
{
    CHECK(0 == 0);
    CHECK_TEXT(0 == 0, "Shouldn't fail");
    CHECK_TRUE(0 == 0);
    CHECK_TRUE_TEXT(0 == 0, "Shouldn't fail");
    CHECK_FALSE(0 != 0);
    CHECK_FALSE_TEXT(0 != 0, "Shouldn't fail");
    LONGS_EQUAL(1,1);
    LONGS_EQUAL_TEXT(1, 1, "Shouldn't fail");
    BYTES_EQUAL(0xab,0xab);
    BYTES_EQUAL_TEXT(0xab, 0xab, "Shouldn't fail");
    CHECK_EQUAL(100,100);
    CHECK_EQUAL_TEXT(100, 100, "Shouldn't fail");
    STRCMP_EQUAL("THIS", "THIS");
    STRCMP_EQUAL_TEXT("THIS", "THIS", "Shouldn't fail");
    DOUBLES_EQUAL(1.0, 1.0, .01);
    DOUBLES_EQUAL_TEXT(1.0, 1.0, .01, "Shouldn't fail");
    POINTERS_EQUAL(0, 0);
    POINTERS_EQUAL_TEXT(0, 0, "Shouldn't fail");
    MEMCMP_EQUAL("THIS", "THIS", 5);
    MEMCMP_EQUAL_TEXT("THIS", "THIS", 5, "Shouldn't fail");
    BITS_EQUAL(0x01, (unsigned char )0x01, 0xFF);
    BITS_EQUAL(0x0001, (unsigned short )0x0001, 0xFFFF);
    BITS_EQUAL(0x00000001, (unsigned long )0x00000001, 0xFFFFFFFF);
    BITS_EQUAL_TEXT(0x01, (unsigned char )0x01, 0xFF, "Shouldn't fail");
    return 0;
}
TEST(MockNamedValueHandlerRepository, installCopier)
{
    TypeForTestingExpectedFunctionCallCopier copier;
    MockNamedValueComparatorsAndCopiersRepository repository;
    repository.installCopier("typeName", copier);
    POINTERS_EQUAL(&copier, repository.getCopierForType("typeName"));
}
Exemple #15
0
TEST(String, Duplicate)
{
    const char *str_test = "test";
    char *str;

    POINTERS_EQUAL(NULL, string_strndup (NULL, 0));

    str = string_strndup (str_test, 0);
    CHECK(str);
    CHECK(str != str_test);
    STRCMP_EQUAL(str, "");
    free (str);

    str = string_strndup (str_test, 2);
    CHECK(str);
    CHECK(str != str_test);
    STRCMP_EQUAL(str, "te");
    free (str);

    str = string_strndup (str_test, 500);
    CHECK(str);
    CHECK(str != str_test);
    STRCMP_EQUAL(str, str_test);
    free (str);
}
TEST(MockNamedValueComparatorRepository, installComparator)
{
	TypeForTestingExpectedFunctionCallComparator comparator;
	MockNamedValueComparatorRepository repository;
	repository.installComparator("typeName", comparator);
	POINTERS_EQUAL(&comparator, repository.getComparatorForType("typeName"));
}
Exemple #17
0
TEST(String, ConvertEscapedChars)
{
    POINTERS_EQUAL(NULL, string_convert_escaped_chars (NULL));
    STRCMP_EQUAL("", string_convert_escaped_chars (""));
    STRCMP_EQUAL("\"", string_convert_escaped_chars ("\\\""));
    STRCMP_EQUAL("\\", string_convert_escaped_chars ("\\\\"));
    STRCMP_EQUAL("\a", string_convert_escaped_chars ("\\a"));
    STRCMP_EQUAL("\a", string_convert_escaped_chars ("\\a"));
    STRCMP_EQUAL("\b", string_convert_escaped_chars ("\\b"));
    STRCMP_EQUAL("\e", string_convert_escaped_chars ("\\e"));
    STRCMP_EQUAL("\f", string_convert_escaped_chars ("\\f"));
    STRCMP_EQUAL("\n", string_convert_escaped_chars ("\\n"));
    STRCMP_EQUAL("\r", string_convert_escaped_chars ("\\r"));
    STRCMP_EQUAL("\t", string_convert_escaped_chars ("\\t"));
    STRCMP_EQUAL("\v", string_convert_escaped_chars ("\\v"));
    STRCMP_EQUAL("\123", string_convert_escaped_chars ("\\0123"));
    STRCMP_EQUAL("\123",
                 string_convert_escaped_chars ("\\0123"));  /* invalid */
    STRCMP_EQUAL("\x41", string_convert_escaped_chars ("\\x41"));
    STRCMP_EQUAL("\x04z", string_convert_escaped_chars ("\\x4z"));
    STRCMP_EQUAL("\u0012zz", string_convert_escaped_chars ("\\u12zz"));
    STRCMP_EQUAL("\U00123456", string_convert_escaped_chars ("\\U00123456"));
    STRCMP_EQUAL("\U00000123zzz",
                 string_convert_escaped_chars ("\\U00123zzz"));
    STRCMP_EQUAL("",
                 string_convert_escaped_chars ("\\U12345678")); /* invalid */
}
Exemple #18
0
TEST(String, Shared)
{
    const char *str1, *str2, *str3;
    int count;

    count = string_hashtable_shared->items_count;

    str1 = string_shared_get ("this is a test");
    CHECK(str1);

    LONGS_EQUAL(count + 1, string_hashtable_shared->items_count);

    str2 = string_shared_get ("this is a test");
    CHECK(str2);
    POINTERS_EQUAL(str1, str2);

    LONGS_EQUAL(count + 1, string_hashtable_shared->items_count);

    str3 = string_shared_get ("this is another test");
    CHECK(str3);
    CHECK(str1 != str3);
    CHECK(str2 != str3);

    LONGS_EQUAL(count + 2, string_hashtable_shared->items_count);

    string_shared_free (str1);
    LONGS_EQUAL(count + 2, string_hashtable_shared->items_count);

    string_shared_free (str2);
    LONGS_EQUAL(count + 1, string_hashtable_shared->items_count);

    string_shared_free (str3);
    LONGS_EQUAL(count + 0, string_hashtable_shared->items_count);
}
TEST(MemoryLeakWarningLocalDetectorTest, localDetectorIsGlobalDetector)
{
    MemoryLeakDetector* globalDetector = MemoryLeakWarningPlugin::getGlobalDetector();
    MemoryLeakWarningPlugin memoryLeakWarningPlugin("TestMemoryLeakWarningPlugin", NULL);
    MemoryLeakDetector* localDetector =  memoryLeakWarningPlugin.getMemoryLeakDetector();
    POINTERS_EQUAL(globalDetector, localDetector);
}
TEST(SimpleString, copyInBufferWithEmptyBuffer)
{
	SimpleString str("Hello World");
	char* buffer= NULL;
	str.copyToBuffer(buffer, 0);
	POINTERS_EQUAL(NULL, buffer);
}
Exemple #21
0
    void assertHasAdcEvent() {

        EventType   *adcEventType = AdcEventType_get();
        Event       *event        = EventSource_poll(_eventSource);

        CHECK( event != NULL);
        POINTERS_EQUAL(adcEventType, Event_getEventType(event));
    }
/* START: nullInterfaceTest */
TEST(LightDriver, NullInterfaceDoesNotCrash)
{
    LightDriver_SetInterface(NULL);
    LightDriver_TurnOn(&testDriver);
    LightDriver_TurnOff(&testDriver);
    LightDriver_Destroy(&testDriver);
    POINTERS_EQUAL(NONSENSE_POINTER, savedDriver);
}
Exemple #23
0
TEST(CallStackTestGroup, GetNameBigLevel)
{
   CallStack   TestCallStack;

   TestSuiteUnwind5(TestCallStack);

   POINTERS_EQUAL(NULL, TestCallStack.GetName(300000));
};
Exemple #24
0
TEST(String, Replace)
{
    regex_t regex;
    char *result;

    /* basic replace */
    POINTERS_EQUAL(NULL, string_replace (NULL, NULL, NULL));
    POINTERS_EQUAL(NULL, string_replace ("string", NULL, NULL));
    POINTERS_EQUAL(NULL, string_replace (NULL, "search", NULL));
    POINTERS_EQUAL(NULL, string_replace (NULL, NULL, "replace"));
    POINTERS_EQUAL(NULL, string_replace ("string", "search", NULL));
    POINTERS_EQUAL(NULL, string_replace ("string", NULL, "replace"));
    POINTERS_EQUAL(NULL, string_replace (NULL, "search", "replace"));

    STRCMP_EQUAL("test abc def", string_replace("test abc def", "xyz", "xxx"));
    STRCMP_EQUAL("test xxx def", string_replace("test abc def", "abc", "xxx"));
    STRCMP_EQUAL("xxx test xxx def xxx",
                 string_replace("abc test abc def abc", "abc", "xxx"));

    /* replace with regex */
    WEE_REPLACE_REGEX(-1, NULL, NULL, NULL, NULL, '$', NULL);
    WEE_REPLACE_REGEX(0, NULL, NULL, "", NULL, '$', NULL);
    WEE_REPLACE_REGEX(0, "string", "string", "", NULL, '$', NULL);
    WEE_REPLACE_REGEX(0, "test abc def", "test abc def", "xyz", "xxx", '$', NULL);
    WEE_REPLACE_REGEX(0, "test xxx def", "test abc def", "abc", "xxx", '$', NULL);
    WEE_REPLACE_REGEX(0, "foo", "test foo", "^(test +)(.*)", "$2", '$', NULL);
    WEE_REPLACE_REGEX(0, "test / ***", "test foo", "^(test +)(.*)", "$1/ $.*2", '$', NULL);
    WEE_REPLACE_REGEX(0, "%%%", "test foo", "^(test +)(.*)", "$.%+", '$', NULL);

    /* replace with a callback */
    /* TODO: write tests for string_replace_with_callback */
}
Exemple #25
0
 void validateNullTokenPointers()
 {
     size_t i;
     
     for (i = 0 ; i < ARRAY_SIZE(m_token.tokenPointers) ; i++)
     {
         POINTERS_EQUAL( NULL, m_token.tokenPointers[i] );
     }
 }
Exemple #26
0
TEST(String, SplitCommand)
{
    char **argv;

    POINTERS_EQUAL(NULL, string_split_command (NULL, ';'));
    POINTERS_EQUAL(NULL, string_split_command ("", ';'));
    argv = string_split_command ("abc;de;fghi", ';');
    CHECK(argv);
    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);

    /* free split with NULL */
    string_free_split_command (NULL);
}
Exemple #27
0
TEST(Utf8, Validity)
{
    char *error;

    /* check 8 bits */
    LONGS_EQUAL(0, utf8_has_8bits (NULL));
    LONGS_EQUAL(0, utf8_has_8bits (""));
    LONGS_EQUAL(0, utf8_has_8bits ("abc"));
    LONGS_EQUAL(1, utf8_has_8bits ("no\xc3\xabl"));

    /* check validity */
    LONGS_EQUAL(1, utf8_is_valid (NULL, NULL));
    LONGS_EQUAL(1, utf8_is_valid (NULL, &error));
    LONGS_EQUAL(1, utf8_is_valid ("", NULL));
    LONGS_EQUAL(1, utf8_is_valid ("", &error));
    LONGS_EQUAL(1, utf8_is_valid ("abc", &error));
    POINTERS_EQUAL(NULL, error);
    LONGS_EQUAL(1, utf8_is_valid (noel_valid, &error));
    POINTERS_EQUAL(NULL, error);
    LONGS_EQUAL(0, utf8_is_valid (noel_invalid, &error));
    POINTERS_EQUAL(noel_invalid + 2, error);

    /* 2 bytes: code point must be in range U+0080-07FF */
    LONGS_EQUAL(0, utf8_is_valid ("\xc0\x80", NULL));  /* U+0   */
    LONGS_EQUAL(0, utf8_is_valid ("\xc1\xbf", NULL));  /* U+7F  */
    LONGS_EQUAL(1, utf8_is_valid ("\xc2\x80", NULL));  /* U+80  */
    LONGS_EQUAL(1, utf8_is_valid ("\xdf\xbf", NULL));  /* U+7FF */

    /* 3 bytes: code point must be in range: U+0800-FFFF */
    LONGS_EQUAL(0, utf8_is_valid ("\xe0\x80\x80", NULL));  /* U+0    */
    LONGS_EQUAL(0, utf8_is_valid ("\xe0\x9f\xbf", NULL));  /* U+7FF  */
    LONGS_EQUAL(0, utf8_is_valid ("\xed\xa0\x80", NULL));  /* U+D800 */
    LONGS_EQUAL(0, utf8_is_valid ("\xed\xbf\xbf", NULL));  /* U+DFFF */
    LONGS_EQUAL(1, utf8_is_valid ("\xe0\xa0\x80", NULL));  /* U+800  */
    LONGS_EQUAL(1, utf8_is_valid ("\xed\x9f\xbf", NULL));  /* U+D7FF */
    LONGS_EQUAL(1, utf8_is_valid ("\xe7\x80\x80", NULL));  /* U+E000 */
    LONGS_EQUAL(1, utf8_is_valid ("\xef\xbf\xbf", NULL));  /* U+FFFF */

    /* 4 bytes: code point must be in range: U+10000-1FFFFF */
    LONGS_EQUAL(0, utf8_is_valid ("\xf0\x80\x80\x80", NULL));  /* U+0      */
    LONGS_EQUAL(0, utf8_is_valid ("\xf0\x8f\xbf\xbf", NULL));  /* U+FFFF   */
    LONGS_EQUAL(1, utf8_is_valid ("\xf0\x90\x80\x80", NULL));  /* U+10000  */
    LONGS_EQUAL(1, utf8_is_valid ("\xf7\xbf\xbf\xbf", NULL));  /* U+1FFFFF */
}
TEST(TrajectoryInitTestGroup, CanInitChunk)
{
    trajectory_chunk_t chunk;
    trajectory_chunk_init(&chunk, (float *)buffer, 3, 2, 100, 10);
    POINTERS_EQUAL((float *)buffer, chunk.buffer);
    CHECK_EQUAL(3, chunk.length);
    CHECK_EQUAL(2, chunk.dimension);
    CHECK_EQUAL(100, (int)chunk.start_time_us);
    CHECK_EQUAL(10, (int)chunk.sampling_time_us);
}
Exemple #29
0
TEST(TLVDecoder, ParseTlv1DataSuccessfully)
{
  Tlv_t tlv;
  // parse
  CHECK(TlvParse(tlv1Data, sizeof(tlv1Data), &tlv));
  // encoding tlv object in the buffer
  POINTERS_EQUAL(tlv1Data, TlvPtr(&tlv));
  // tag class
  LONGS_EQUAL(TAG_CLASS_APP, TagTagClass(&tlv.tag));
  // Primitive or constructed
  CHECK(TagIsPorC(&tlv.tag));
  // tag number
  LONGS_EQUAL(0x10, TagTagNum(&tlv.tag));
  // length
  LONGS_EQUAL(0x43, TlvDataLen(&tlv));
  // value
  POINTERS_EQUAL(&tlv1Data[2], TlvValue(&tlv));
  LONGS_EQUAL(TlvDataLen(&tlv), TlvDataCapacity(&tlv));
}
Exemple #30
0
TEST(filter, create_fail_invalid_closing_brackets){
	char * filter_str;
	filter_pt get_filter;
	//test missing closing brackets in substring
	mock().expectNCalls(6, "framework_log");
	filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3=at(tr3)))");
	get_filter = filter_create(filter_str);
	POINTERS_EQUAL(NULL, get_filter);
	free(filter_str);
	mock().checkExpectations();

	//test missing closing brackets in value
	mock().expectNCalls(5, "framework_log");
	filter_str = my_strdup("(&(test_attr1=attr1)(|(test_attr2=attr2)(test_attr3>=att(r3)))");
	get_filter = filter_create(filter_str);
	POINTERS_EQUAL(NULL, get_filter);
	free(filter_str);
	mock().checkExpectations();
}