Exemplo n.º 1
0
LONGBOW_TEST_CASE(Global, longBowTestCaseClipBoard_Set)
{
    char *shared = longBowMemory_StringCopy("shared data");

    LongBowTestCaseClipBoard *clipboard = longBowTestCaseClipBoard_Create(shared);

    char *expected = longBowMemory_StringCopy("expected");

    longBowTestCaseClipBoard_Set(clipboard, expected);
    char *actual = longBowTestCaseClipBoard_Get(clipboard);
    assertTrue(strcmp(expected, actual) == 0, "Expected %s, actual %s", expected, actual);

    longBowTestCaseClipBoard_Destroy(&clipboard);
    longBowMemory_Deallocate((void **) &shared);
    longBowMemory_Deallocate((void **) &expected);
}
Exemplo n.º 2
0
LongBowArrayList *
longBowString_Tokenise(const char *string, const char *separators)
{
    LongBowArrayList *result = longBowArrayList_Create(longBowMemory_Deallocate);
    if (string != NULL) {
        char *workingCopy = longBowMemory_StringCopy(string);
        
        char *p = strtok(workingCopy, separators);
        while (p) {
            longBowArrayList_Add(result, longBowMemory_StringCopy(p));
            p = strtok(NULL, separators);
        }
        
        longBowMemory_Deallocate((void **) &workingCopy);
    }
    
    return result;
}
Exemplo n.º 3
0
bool
longBowProperties_Set(LongBowProperties *properties, const char *name, const char *value)
{
    bool result = false;

    _Property *property = _longBowProperties_Get(properties, name);
    if (property == NULL) {
        property = longBowMemory_Allocate(sizeof(_Property));
        property->name = longBowMemory_StringCopy(name);
        property->value = longBowMemory_StringCopy(value);
        longBowArrayList_Add(properties->list, property);
        result = true;
    } else {
        longBowMemory_Deallocate((void **) &property->value);
        property->value = longBowMemory_StringCopy(value);
    }
    return result;
}
Exemplo n.º 4
0
LongBowString *
longBowString_CreateString(const char *string)
{
    LongBowString *result = longBowMemory_Allocate(sizeof(LongBowString));
    result->end = strlen(string) + 1;
    result->buffer = longBowMemory_StringCopy(string);
    result->cursor = result->end - 1;
    result->buffer[result->cursor] = 0;
    
    return result;
}
Exemplo n.º 5
0
LONGBOW_TEST_CASE(Global, longBowTestCaseClipBoard_CreateDestroy)
{
    uint64_t allocations = longBowMemory_OutstandingAllocations();
    char *shared = longBowMemory_StringCopy("shared data");

    LongBowTestCaseClipBoard *clipboard = longBowTestCaseClipBoard_Create(shared);
    assertNotNull(clipboard, "Expected non-null result from longBowTestCaseClipBoard_Create");

    longBowTestCaseClipBoard_Destroy(&clipboard);
    longBowMemory_Deallocate((void **) &shared);

    assertTrue(longBowMemory_OutstandingAllocations() == allocations,
               "Memory leaks %" PRId64, longBowMemory_OutstandingAllocations());
}