Esempio n. 1
0
static char *test_split()
{
    const char *should_be = "hello world dada";
    char *delim = " ";
    const char **ret;
    int count;

    ret = (const char **) split(should_be, " ", &count);
    mu_assert("space", strcmp(should_be, join(ret, count, delim)) == 0);

    ret = (const char **) split(should_be, "abc", &count);
    mu_assert("non-exists delim",
              strcmp(should_be, join(ret, count, delim)) == 0);
    mu_assert("non-exists delim", count == 1);

    ret = (const char **) split("hello<3world<3dada", "<3", &count);
    mu_assert("long delim", strcmp(should_be, join(ret, count, delim)) == 0);

    ret = (const char **) split("", " ", &count);
    mu_assert("empty string", count == 1);
    mu_assert("empty string", strcmp(ret[0], "") == 0);

    ret = (const char **) split("a", "a", &count);
    mu_assert("same as delim", count == 2);
    mu_assert("same as delim",
              strcmp(ret[0], "") == 0 && strcmp(ret[1], "") == 0);

    ret = (const char **) split("abc", "a", &count);
    mu_assert("head split", count == 2);
    mu_assert("head split",
              strcmp(ret[0], "") == 0 && strcmp(ret[1], "bc") == 0);
    
    ret = (const char **) split("abc", "c", &count);
    mu_assert("tail split", count == 2);
    mu_assert("tail split",
              strcmp(ret[0], "ab") == 0 && strcmp(ret[1], "") == 0);

    return 0;
}
Esempio n. 2
0
char *test_dlopen()
{
	lib  = dlopen(lib_file, RTLD_NOW);
	mu_assert(lib != NULL, "Failed to open the library to test.");
	return NULL;
}
Esempio n. 3
0
// ----------------------------------------------------------------
static char * test_canonical_mod() {
	mu_assert("error: canonical_mod -7", mlr_canonical_mod(-7, 5) == 3);
	mu_assert("error: canonical_mod -6", mlr_canonical_mod(-6, 5) == 4);
	mu_assert("error: canonical_mod -5", mlr_canonical_mod(-5, 5) == 0);
	mu_assert("error: canonical_mod -4", mlr_canonical_mod(-4, 5) == 1);
	mu_assert("error: canonical_mod -3", mlr_canonical_mod(-3, 5) == 2);
	mu_assert("error: canonical_mod -2", mlr_canonical_mod(-2, 5) == 3);
	mu_assert("error: canonical_mod -1", mlr_canonical_mod(-1, 5) == 4);
	mu_assert("error: canonical_mod  0", mlr_canonical_mod(0, 5) == 0);
	mu_assert("error: canonical_mod  1", mlr_canonical_mod(1, 5) == 1);
	mu_assert("error: canonical_mod  2", mlr_canonical_mod(2, 5) == 2);
	mu_assert("error: canonical_mod  3", mlr_canonical_mod(3, 5) == 3);
	mu_assert("error: canonical_mod  4", mlr_canonical_mod(4, 5) == 4);
	mu_assert("error: canonical_mod  5", mlr_canonical_mod(5, 5) == 0);
	mu_assert("error: canonical_mod  6", mlr_canonical_mod(6, 5) == 1);
	mu_assert("error: canonical_mod  7", mlr_canonical_mod(7, 5) == 2);
	return 0;
}
Esempio n. 4
0
char *test_darray_operations()
{
    darray_t *array = darray_create(sizeof(int), 100);
    mu_assert(array != NULL, "darray_create failed.");
    mu_assert(array->contents != NULL, "contents are wrong in darray");
    mu_assert(array->end == 0, "end isn't at the right spot");
    mu_assert(array->element_size == sizeof(int), "element size is wrong.");
    mu_assert(array->max == 100, "wrong max length on initial size");

    int *val1 = darray_new(array);
    mu_assert(val1 != NULL, "failed to make a new element");

    int *val2 = darray_new(array);
    mu_assert(val2 != NULL, "failed to make a new element");

    darray_set(array, 0, val1);
    darray_set(array, 1, val2);

    mu_assert(darray_get(array, 0) == val1, "Wrong first value.");
    mu_assert(darray_get(array, 1) == val2, "Wrong second value.");

    int *val_check = darray_remove(array, 0);
    mu_assert(val_check != NULL, "Should not get NULL.");
    mu_assert(*val_check == *val1, "Should get the first value.");
    mu_assert(darray_get(array, 0) == NULL, "Should be gone.");
    darray_free(val_check);

    val_check = darray_remove(array, 1);
    mu_assert(val_check != NULL, "Should not get NULL.");
    mu_assert(*val_check == *val2, "Should get the first value.");
    mu_assert(darray_get(array, 1) == NULL, "Should be gone.");
    darray_free(val_check);

    signed int old_max = array->max;
    darray_expand(array);
    mu_assert(array->max == old_max + array->expand_rate, "Wrong size after expand.");

    darray_contract(array);
    mu_assert(array->max == array->expand_rate + 1, "Should stay at the expand_rate at least.");

    darray_contract(array);
    mu_assert(array->max == array->expand_rate + 1, "Should stay at the expand_rate at least.");

    int i = 0;
    for(i = 0; i < 1000; i++) {
        int *val = darray_new(array);
        darray_attach(array, val); 
        *val = i * 333;
        darray_push(array, val);
    }

    mu_assert(array->max == 1201, "Wrong max size.");

    for(i = 999; i > 0; i--) {
        int *val = darray_pop(array);
        mu_assert(val != NULL, "Shouldn't get a NULL.");
        mu_assert(*val == i * 333, "Wrong value.");
        darray_free(val);
    }

    darray_destroy(array);
 
    return NULL;
}
Esempio n. 5
0
static char* test_simple()
{
  lua_sandbox* sb = lsb_create(NULL, "lua/simple.lua", 65765, 1000,
                               1024);
  mu_assert(sb, "lsb_create() received: NULL");

  int result = lsb_init(sb, NULL);
  mu_assert(result == 0, "lsb_init() received: %d %s", result,
            lsb_get_error(sb));

  unsigned u = lsb_usage(sb, LSB_UT_MEMORY, LSB_US_CURRENT);
  mu_assert(u > 0, "Current memory usage received: %u", u);
  printf("cur_mem %u\n", u);

  u = lsb_usage(sb, LSB_UT_MEMORY, LSB_US_MAXIMUM);
  mu_assert(u > 0, "Maximum memory usage received: %u", u);
  printf("max_mem %u\n", u);

  u = lsb_usage(sb, LSB_UT_MEMORY, LSB_US_LIMIT);
  mu_assert(u == 65765, "Memory limit received: %u", u);

  u = lsb_usage(sb, LSB_UT_INSTRUCTION, LSB_US_CURRENT);
  mu_assert(u == 7, "Current instructions received: %u", u);

  u = lsb_usage(sb, LSB_UT_INSTRUCTION, LSB_US_MAXIMUM);
  mu_assert(u == 7, "Maximum instructions received: %u", u);
  printf("max_ins %u\n", u);

  u = lsb_usage(sb, LSB_UT_INSTRUCTION, LSB_US_LIMIT);
  mu_assert(u == 1000, "Instruction limit received: %u", u);

  u = lsb_usage(sb, LSB_UT_OUTPUT, LSB_US_CURRENT);
  mu_assert(u == 0, "Current output received: %u", u);

  u = lsb_usage(sb, LSB_UT_OUTPUT, LSB_US_MAXIMUM);
  mu_assert(u == 0, "Maximum output received: %u", u);
  printf("max_out %u\n", u);

  u = lsb_usage(sb, LSB_UT_OUTPUT, LSB_US_LIMIT);
  mu_assert(u == 1024, "Output limit received: %u", u);

  u = lsb_usage(sb, LSB_UT_OUTPUT, LSB_US_LIMIT);
  mu_assert(u == 1024, "Output limit received: %u", u);

  lsb_state s = lsb_get_state(sb);
  mu_assert(s == LSB_RUNNING, "lsb_get_state() received: %d", s);

  e = lsb_destroy(sb, "simple.preserve");
  mu_assert(!e, "lsb_destroy() received: %s", e);

  return NULL;
}
Esempio n. 6
0
static char* test_cbuf_delta()
{
  const char* outputs[] = {
    "{\"time\":0,\"rows\":3,\"columns\":3,\"seconds_per_row\":1,\"column_info\":[{\"name\":\"Add_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Set_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Get_column\",\"unit\":\"count\",\"aggregation\":\"sum\"}]}\n1\t1\t1\n2\t1\t2\n3\t1\t3\n"
#ifdef LUA_JIT
    , "{\"time\":0,\"rows\":3,\"columns\":3,\"seconds_per_row\":1,\"column_info\":[{\"name\":\"Add_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Set_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Get_column\",\"unit\":\"count\",\"aggregation\":\"sum\"}]}\n0\t1\t1\t1\n1\t2\t1\t2\n2\t3\t1\t3\n"
#else
    , "{\"time\":0,\"rows\":3,\"columns\":3,\"seconds_per_row\":1,\"column_info\":[{\"name\":\"Add_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Set_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Get_column\",\"unit\":\"count\",\"aggregation\":\"sum\"}]}\n1\t2\t1\t2\n2\t3\t1\t3\n0\t1\t1\t1\n"
#endif
    , "{\"time\":0,\"rows\":3,\"columns\":3,\"seconds_per_row\":1,\"column_info\":[{\"name\":\"Add_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Set_column\",\"unit\":\"count\",\"aggregation\":\"sum\"},{\"name\":\"Get_column\",\"unit\":\"count\",\"aggregation\":\"sum\"}]}\n1\t1\t1\n2\t1\t2\n3\t1\t3\n"
    , ""
    , NULL
  };

  lua_sandbox* sb = lsb_create(NULL, "lua/circular_buffer_delta.lua",
                               32767, 1000, 32767);
  mu_assert(sb, "lsb_create() received: NULL");

  int result = lsb_init(sb, NULL);
  mu_assert(result == 0, "lsb_init() received: %d %s", result,
            lsb_get_error(sb));
  lsb_add_function(sb, &write_output, "write");

  process(sb, 0);
  process(sb, 1e9);
  process(sb, 1e9);
  process(sb, 2e9);
  process(sb, 2e9);
  process(sb, 2e9);
  result = report(sb, 0);
  mu_assert(result == 0, "report() received: %d", result);
  mu_assert(strcmp(outputs[0], written_data) == 0, "received: %s",
            written_data);

  result = report(sb, 1);
  mu_assert(result == 0, "report() received: %d", result);
  mu_assert(strcmp(outputs[1], written_data) == 0, "received: %s",
            written_data);

  result = report(sb, 0);
  mu_assert(result == 0, "report() received: %d", result);
  mu_assert(strcmp(outputs[2], written_data) == 0, "received: %s",
            written_data);

  result = report(sb, 1);
  mu_assert(result == 0, "report() received: %d", result);
  mu_assert(strcmp(outputs[3], written_data) == 0, "received: %s",
            written_data);

  e = lsb_destroy(sb, "circular_buffer_delta.preserve");
  mu_assert(!e, "lsb_destroy() received: %s", e);

  return NULL;
}
Esempio n. 7
0
static char * test_125reais() {
       mu_assert(" Erro. Valor 125 foi aceito", testa_valor(125) ==0);
       return 0;
       }
Esempio n. 8
0
static char *test_init()
{
	mu_assert("ERROR: gotr_init failed", gotr_init() == 1);
	return 0;
}
Esempio n. 9
0
static char * test_15reais() {
    mu_assert("Erro! Aceitou 15 Reais",testa_valor(15) == 0);
    return 0;
}
Esempio n. 10
0
static char * test_20reais() {
    mu_assert("Erro. Valor 20 nao foi aceito!",testa_valor(20) != 0);
    return 0;
}
Esempio n. 11
0
static char * test_retorno0(){
       mu_assert("Erro! Deveria retornar X", conta_notas(0) == "X");
       return 0;
}
Esempio n. 12
0
static char * test_retorno170(){
       mu_assert("Erro! Deveria retornar C1Q1V1", conta_notas(170) == "C1Q1V1");
       return 0;      
}
Esempio n. 13
0
// test for big number of elements
static char *test_RadixMap_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");
    mu_assert(make_random(map), "Didn't make a random fake radix map.");

    RadixMap_sort(map);
    mu_assert(check_order(map), "Failed to properly sort the RadixMap.");

    mu_assert(test_search(map), "Failed the search test.");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search.");

    RadixMap_destroy(map);

    map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");

    debug("PUSHING VALUES");
    mu_assert(push_random_values(map), "Didn't push random values.");
    debug("VALUES PUSHED!");

    mu_assert(check_order(map), "Map wasn't sorted after pushes.");

    debug("DOING DELETES");
    while(map->end > 0) {
        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "Should get a result.");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it.");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete.");

        // test that the end is now the old value, but uint32 max so it trails off
        mu_assert(check_order(map), "RadixMap didn't stay sorted after delete.");
    }

    RadixMap_destroy(map);

    return NULL;
}
Esempio n. 14
0
char *test_failures()
{
	mu_assert(check_function("fail_on_purpose", "Hello", 1), "fail_on_purpose should fail");
	return NULL;
}
Esempio n. 15
0
static char * test_foo() {
    mu_assert("error, foo != 7", foo == 7);
    return 0;
}
Esempio n. 16
0
char *test_dlclose()
{
	int rc = dlclose(lib);
	mu_assert(rc == 0, "Failed to close lib");
	return NULL;
}
Esempio n. 17
0
char *test_empty(){
    IntList *il = create_int_list();
    mu_assert(int_list_empty(il), "La lista de enteros esta vacia");
    return NULL;
}
Esempio n. 18
0
static char *test_vector_resize(void)
{
    {
        int err; 
        
        //Verify that vector_resize returns 0 on NULL vec object
        err = vector_resize(NULL, 10);
        mu_assert("vector_resize returns positive on NULL vec\n", err == -1);
    }

    {
        struct vector *vec;
        int err; 
        
        //Verify vector_resize detects overflow   
        vec = vector_create(10, sizeof(int));
        err = vector_resize(vec, SIZE_MAX);
        mu_assert("vector_resize returns no error on invalid size\n", err == -1);
        err = vector_resize(vec, 20);
        mu_assert("vector_resize returns non-0 on valid size\n", err == 0);
        vector_destroy(vec);
    }

    {
        struct vector *vec;
        int err; 
        size_t size;
        int i;
        
        vec = vector_create(10, sizeof(int));
        err = vector_resize(vec, 100);
        mu_assert("vector_resize returns error on growing\n", err == 0);

        //Verify length is correct after growing with vector_resize    
        size = vector_length(vec);
        mu_assert("wrong vector length reported\n", size == 100);

        //Verify the vector is initialized to 0 after resize
        for (i = 0; i < 100; i++) {
            int *j = vector_get(vec, i);
            mu_assert("resized vector not initialized to zero\n", *j == 0);
        }

        vector_destroy(vec);
    }

    {
        struct vector *vec;
        int err; 
        size_t size;
        
        vec = vector_create(100, sizeof(int));
        
        err = vector_resize(vec, 10);
        mu_assert("vector_resize returns error on shrinking\n", err == 0);
        
        //Verify length is correct after shrinking with vector_resize    
        size = vector_length(vec);
        mu_assert("wrong vector length reported\n", size == 10);
        vector_destroy(vec);
    }

    {
        /**
         * Fill up the vector with data and verify it is still there after
         * growing the vector
         */
        struct vector *vec;
        int i;

        vec = vector_create(10, sizeof(int));

        for (i = 0; i < 10; i++) {
            vector_set(vec, i, &i); 
        }

        vector_resize(vec, 100);

        for (i = 0; i < 10; i++) {
            int *j = vector_get(vec, i);
            mu_assert("vector contents not copied after resize\n", *j == i);
        }
    }

    {
        /**
         * Fill up the vector with data and verify it is still there after
         * shrinking the vector
         */
        struct vector *vec;
        int i;

        vec = vector_create(100, sizeof(int));

        for (i = 0; i < 100; i++) {
            vector_set(vec, i, &i); 
        }

        vector_resize(vec, 10);

        for (i = 0; i < 10; i++) {
            int *j = vector_get(vec, i);
            mu_assert("vector contents not copied after resize\n", *j == i);
        }
    }
   
    return 0;
}
Esempio n. 19
0
char *test_has_int_1(){
    IntList *il = create_int_list();
    int_list_add(il, 1);
    mu_assert(il->first->i == 1, "La lista de enteros tiene al elemento 1");
    return NULL;
}
Esempio n. 20
0
static char* test_output()
{
  const char* outputs[] = {
    "{\"table\":{\"value\":1}}\n1.2 string nil true false"
    , ""
#ifdef LUA_JIT
    , "{\"table\":{\"Timestamp\":0,\"Value\":0,\"StatisticValues\":[{\"SampleCount\":0,\"Sum\":0,\"Maximum\":0,\"Minimum\":0},{\"SampleCount\":0,\"Sum\":0,\"Maximum\":0,\"Minimum\":0}],\"Unit\":\"s\",\"MetricName\":\"example\",\"Dimensions\":[{\"Name\":\"d1\",\"Value\":\"v1\"},{\"Name\":\"d2\",\"Value\":\"v2\"}]}}\n"
#else
    , "{\"table\":{\"StatisticValues\":[{\"Minimum\":0,\"SampleCount\":0,\"Sum\":0,\"Maximum\":0},{\"Minimum\":0,\"SampleCount\":0,\"Sum\":0,\"Maximum\":0}],\"Dimensions\":[{\"Name\":\"d1\",\"Value\":\"v1\"},{\"Name\":\"d2\",\"Value\":\"v2\"}],\"MetricName\":\"example\",\"Timestamp\":0,\"Value\":0,\"Unit\":\"s\"}}\n"
#endif
    , "{\"table\":{\"a\":{\"y\":2,\"x\":1}}}\n"
    , "{\"table\":[1,2,3]}\n"
    , "{\"table\":{\"x\":1}}\n"
    , "{\"array\":[1,2,3]}\n"
    , "{\"table\":{}}\n"
    , "{\"table\":{\"special\\tcharacters\":\"\\\"\\t\\r\\n\\b\\f\\\\\\/\"}}\n"
    , "\x10\x80\x94\xeb\xdc\x03\x1a\x04\x74\x79\x70\x65\x22\x06\x6c\x6f\x67\x67\x65\x72\x28\x09\x32\x07\x70\x61\x79\x6c\x6f\x61\x64\x3a\x0b\x65\x6e\x76\x5f\x76\x65\x72\x73\x69\x6f\x6e\x4a\x08\x68\x6f\x73\x74\x6e\x61\x6d\x65"
    , "\x10\x80\x94\xeb\xdc\x03\x52\x12\x0a\x05\x63\x6f\x75\x6e\x74\x10\x03\x39\x00\x00\x00\x00\x00\x00\xf0\x3f"
    , "\x10\x80\x94\xeb\xdc\x03\x52\x25\x0a\x06\x63\x6f\x75\x6e\x74\x73\x10\x03\x39\x00\x00\x00\x00\x00\x00\x00\x40\x39\x00\x00\x00\x00\x00\x00\x08\x40\x39\x00\x00\x00\x00\x00\x00\x10\x40"
    , "\x10\x80\x94\xeb\xdc\x03\x52\x19\x0a\x05\x63\x6f\x75\x6e\x74\x10\x03\x1a\x05\x63\x6f\x75\x6e\x74\x39\x00\x00\x00\x00\x00\x00\x14\x40"
    , "\x10\x80\x94\xeb\xdc\x03\x52\x2c\x0a\x06\x63\x6f\x75\x6e\x74\x73\x10\x03\x1a\x05\x63\x6f\x75\x6e\x74\x39\x00\x00\x00\x00\x00\x00\x18\x40\x39\x00\x00\x00\x00\x00\x00\x1c\x40\x39\x00\x00\x00\x00\x00\x00\x20\x40"
#ifdef LUA_JIT
    , "\x10\x80\x94\xeb\xdc\x03\x52\x13\x0a\x06\x6e\x75\x6d\x62\x65\x72\x10\x03\x39\x00\x00\x00\x00\x00\x00\xf0\x3f\x52\x0f\x0a\x05\x62\x6f\x6f\x6c\x73\x10\x04\x40\x01\x40\x00\x40\x00\x52\x10\x0a\x06\x73\x74\x72\x69\x6e\x67\x22\x06\x73\x74\x72\x69\x6e\x67\x52\x0a\x0a\x04\x62\x6f\x6f\x6c\x10\x04\x40\x01\x52\x2d\x0a\x07\x6e\x75\x6d\x62\x65\x72\x73\x10\x03\x1a\x05\x63\x6f\x75\x6e\x74\x39\x00\x00\x00\x00\x00\x00\xf0\x3f\x39\x00\x00\x00\x00\x00\x00\x00\x40\x39\x00\x00\x00\x00\x00\x00\x08\x40\x52\x15\x0a\x07\x73\x74\x72\x69\x6e\x67\x73\x22\x02\x73\x31\x22\x02\x73\x32\x22\x02\x73\x33"
#else
    , "\x10\x80\x94\xeb\xdc\x03\x52\x13\x0a\x06\x6e\x75\x6d\x62\x65\x72\x10\x03\x39\x00\x00\x00\x00\x00\x00\xf0\x3f\x52\x2d\x0a\x07\x6e\x75\x6d\x62\x65\x72\x73\x10\x03\x1a\x05\x63\x6f\x75\x6e\x74\x39\x00\x00\x00\x00\x00\x00\xf0\x3f\x39\x00\x00\x00\x00\x00\x00\x00\x40\x39\x00\x00\x00\x00\x00\x00\x08\x40\x52\x0f\x0a\x05\x62\x6f\x6f\x6c\x73\x10\x04\x40\x01\x40\x00\x40\x00\x52\x0a\x0a\x04\x62\x6f\x6f\x6c\x10\x04\x40\x01\x52\x10\x0a\x06\x73\x74\x72\x69\x6e\x67\x22\x06\x73\x74\x72\x69\x6e\x67\x52\x15\x0a\x07\x73\x74\x72\x69\x6e\x67\x73\x22\x02\x73\x31\x22\x02\x73\x32\x22\x02\x73\x33"
#endif
    , "\x10\x80\x94\xeb\xdc\x03\x52\x8d\x01\x0a\x06\x73\x74\x72\x69\x6e\x67\x22\x82\x01\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39"
    , NULL
  };

  lua_sandbox* sb = lsb_create(NULL, "lua/output.lua", 100000,
                               1000, 63 * 1024);
  mu_assert(sb, "lsb_create() received: NULL");

  int result = lsb_init(sb, NULL);
  mu_assert(result == 0, "lsb_init() received: %d %s", result,
            lsb_get_error(sb));
  lsb_add_function(sb, &write_output, "write");

  for (int x = 0; outputs[x]; ++x) {
    result = process(sb, x);
    mu_assert(!result, "process() failed: %d %s", result, lsb_get_error(sb));
    if (outputs[x][0]) {
      if (outputs[x][0] == 0x10) {
        size_t header = 18;
        if (memcmp(outputs[x], written_data + header, written_data_len - header) != 0) {
          char hex_data[LSB_OUTPUT + 1];
          size_t z = 0;
          for (size_t y = header; y < written_data_len; ++y, z += 3) {
            snprintf(hex_data + z, LSB_OUTPUT - z, "%02x ", (unsigned char)written_data[y]);
          }
          hex_data[z] = 0;
          mu_assert(0, "test: %d received: %s", x, hex_data);
        }
      } else {
        mu_assert(strcmp(outputs[x], written_data) == 0, "test: %d received: %s",
                  x, written_data);
      }
    }
  }

  e = lsb_destroy(sb, "circular_buffer.preserve");
  mu_assert(!e, "lsb_destroy() received: %s", e);

  return NULL;
}
static char *test_CompareTwoPeopleByName_SameEmptyObject() {
    Person *testPerson = (Person *) malloc(sizeof(Person));
    mu_assert("error in compareTwoPeopleByName_SameEmptyObject", compareTwoPeopleByName(testPerson, testPerson) == 0);
    free(testPerson);
    return 0;
}
Esempio n. 22
0
static char * test_bar() {
    mu_assert("error, bar != 2", bar == 2);
    return 0;
}
Esempio n. 23
0
char *test_simple_repetitions()
{
    m = pattern_match("ZEEEED", strlen("ZEEEED"), "ZE*D");
    mu_assert(m != NULL, "Should match.");

    m = pattern_match("ZEEEED", strlen("ZEEEED"), "ZE*ED");
    mu_assert(m != NULL, "Should match.");

    m = pattern_match("ZED", strlen("ZEEEED"), "ZE*ED");
    mu_assert(m != NULL, "Should match.");

    m = pattern_match("ZD", strlen("ZD"), "ZE*D");
    mu_assert(m != NULL, "Should match.");

    m = pattern_match("ZEEEED", strlen("ZEEEED"), "ZX*D");
    mu_assert(m == NULL, "Should not match.");

    m = pattern_match("ZEEEED", strlen("ZEEEED"), "Z.*D");
    mu_assert(m != NULL, "Should match.");

    m = pattern_match("ZXXXXD", strlen("ZXXXXD"), "ZE.*D");
    mu_assert(m == NULL, "Should not match.");

    m = pattern_match("ZEEEED", strlen("ZEEEED"), "ZE+D");
    mu_assert(m != NULL, "Should match.");

    m = pattern_match("ZD", strlen("ZEEEED"), "ZE+D");
    mu_assert(m == NULL, "Should not match.");

    m = pattern_match("ZEEEED", strlen("ZEEEED"), "ZE-D");
    mu_assert(m != NULL, "Should match.");

    m = pattern_match("ZD", strlen("ZEEEED"), "ZE-D");
    mu_assert(m != NULL, "Should match.");

    return NULL;
}
Esempio n. 24
0
// ----------------------------------------------------------------
static char * test_scanners() {
	mu_assert("error: mlr_alloc_string_from_double", streq(mlr_alloc_string_from_double(4.25, "%.4f"), "4.2500"));
	mu_assert("error: mlr_alloc_string_from_ull", streq(mlr_alloc_string_from_ull(12345LL), "12345"));
	mu_assert("error: mlr_alloc_string_from_int", streq(mlr_alloc_string_from_int(12345), "12345"));
	return 0;
}
Esempio n. 25
0
static char * test_push_pop() {
  int i;

  stack_reset();

  /* push one, pop one */
  push(INT_MAX);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MAX);
  sprintf(msg, "ERROR: %d: should be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: should pop INT_MIN when empty", __LINE__);
  mu_assert(msg, pop() == INT_MIN);
  sprintf(msg, "ERROR: %d: should pop INT_MIN when empty", __LINE__);
  mu_assert(msg, pop() == INT_MIN);
  

  /* push three, pop two */
  push(INT_MAX);
  push(-1);
  push(44);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 44);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == -1);
  
  /* push three, pop one */
  push(1);
  push(2);
  push(3);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 3);

  /* should have three on intstack - add till full */
  for (i = 30; ! stack_is_full(); i++) {
    push(i);
  }

  sprintf(msg, "ERROR: %d: should be full", __LINE__);
  mu_assert(msg, stack_is_full());

  /* now pop all remaining and test values */
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 36);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 35);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 34);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 33);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 32);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 31);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 30);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 2);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 1);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MAX);
  sprintf(msg, "ERROR: %d: should be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MIN);


  return EXIT_SUCCESS;
}