Exemple #1
0
void TestCuStringNew(CuTest* tc)
{
	CuString* str = CuStringNew();
	CuAssertTrue(tc, 0 == str->length);
	CuAssertTrue(tc, 0 != str->size);
	CuAssertStrEquals(tc, "", str->buffer);
}
Exemple #2
0
void TestCuSuiteDetails_MultiplePasses(CuTest* tc)
{
	CuSuite ts;
	CuTest tc1, tc2;
	CuString details;
	const char* expected;

	CuSuiteInit(&ts);
	CuTestInit(&tc1, "TestPasses", TestPasses);
	CuTestInit(&tc2, "TestPasses", TestPasses);
	CuStringInit(&details);

	CuSuiteAdd(&ts, &tc1);
	CuSuiteAdd(&ts, &tc2);
	CuSuiteRun(&ts);

	CuSuiteDetails(&ts, &details);

	CuAssertTrue(tc, ts.count == 2);
	CuAssertTrue(tc, ts.failCount == 0);

	expected =
		"OK (2 tests)\n";

	CuAssertStrEquals(tc, expected, details.buffer);
}
static void test_move_illegal(CuTest * tc) {
  void (*event_cb)(const char *, ...);
  unit * u;
  region * r, ** path;

  svc.reset();

  event_cb = svc.add_event;
  svc.add_event = record_events;
  num_events = 0;

  r = svc.regions->create(0, 0);
  u = svc.units->create();
  svc.regions->add_unit(r, u);
  kv_seti(&u->stats, "speed", 1);

  path = malloc(sizeof(region *)*2);
  path[0] = svc.regions->create(2, 0);
  path[1] = 0;
  u_set_moves(u, path);

  svc.units->set_region(u, r);
  do_movement();
  CuAssertPtrEquals(tc, r, svc.units->get_region(u));

  CuAssertIntEquals(tc, 1, num_events);
  CuAssertStrEquals(tc, "illegal_move", events[0]);
  svc.add_event = event_cb;
}
void TestReverseWithShortString(CuTest *tc) {
  DHString *string = dhstring_new("Hello world!");
  dhstring_reverse_in_place(string);
  const char *actual = dhstring_to_array(string);
  const char *expected = "!dlrow olleH";
  CuAssertStrEquals(tc, expected, actual);
}
Exemple #5
0
void TestCuStringAppendNULL(CuTest* tc)
{
	CuString* str = CuStringNew();
	CuStringAppend(str, NULL);
	CuAssertIntEquals(tc, 4, str->length);
	CuAssertStrEquals(tc, "NULL", str->buffer);
}
void TestReverseWithEmptyString(CuTest *tc) {
  DHString *string = dhstring_new("");
  dhstring_reverse_in_place(string);
  const char *actual = dhstring_to_array(string);
  const char *expected = "";
  CuAssertStrEquals(tc, expected, actual);
}
void testSetNormalise(CuTest *tc) {
	char* input;
	char* expected;
	setStatus ss;

	// TODO: Boundary Case - Max number of chars
	// TODO: Boundary Case - Max number of members

	// Boundary Case - 29 chars - Should be OK
	input = strdup("a i a i a i a e a i a a i a i");   expected = "a e i"; 
	ss = setNormalise(input); CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setOK, ss);

	// Boundary Case - 30 chars - ON THE LIMIT - Should return setBadSet
	input = strdup("a i a i a i a e a i a a i a ii");   expected = "a i a i a i a e a i a a i a ii";  // "a e i ii"; 
	ss = setNormalise(input); CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setBadSet, ss);

	// Boundary Case - 9 members - Should be OK
	input = strdup("j i h g e d c b a");   expected = "a b c d e g h i j"; 
	ss = setNormalise(input); CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setOK, ss);

	// Boundary Case - 10 members - Should return setBadSet
	input = strdup("j i h g e d c b a z");   expected = "a b c d e g h i j z"; 
	ss = setNormalise(input); CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setBadSet, ss);

	input = strdup("a i a i h g f e d c b a i a i");   expected = "a b c d e f g h i"; ss = setNormalise(input);
	CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setOK, ss);

	// General Case - duplicates and ordering
	input = strdup("i h g f e d c b a");               expected ="a b c d e f g h i";ss = setNormalise(input);
	CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setOK, ss);

	// General Case - duplicates and ordering
	input = strdup("c c c c c c d a");                 expected = "a c d";           ss = setNormalise(input);
	CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setOK, ss);

	// General Case - duplicates and ordering
	input = strdup("beta alpha beta gamma alpha");     expected = "alpha beta gamma"; ss = setNormalise(input);
	CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setOK, ss);

	// Boundary Case - empty set supplied
	input = strdup("");                                expected = "";                 ss = setNormalise(input);
	CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setOK, ss);

	// Exceptional Case - NULL supplied
	input = NULL;                                      expected = NULL;               ss = setNormalise(input);
	CuAssertStrEquals(tc, expected, input); CuAssertIntEquals(tc, setBadSet, ss);
} //testSetNormalise
test_uri_norm_scheme_2(CuTest *tc)
{
	char *seed = strdup("hTTp://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, seed);
	uri_norm_scheme(&uri);
	CuAssertStrEquals(tc, *uri.uri_scheme, "http" );
}
Exemple #9
0
static void snprintf_underflow(CuTest *tc)
{
    char buf[20];
    int rv;

    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001);
    CuAssertIntEquals(tc, 4, rv);
    CuAssertStrEquals(tc, "0.00", buf);
    
    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001);
    CuAssertIntEquals(tc, 4, rv);
    CuAssertStrEquals(tc, "0.00", buf);
    
    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01);
    CuAssertIntEquals(tc, 4, rv);
    CuAssertStrEquals(tc, "0.01", buf);
}
Exemple #10
0
static void test_json_write(CuTest * tc) {
    char buf[256];
    cJSON * json = cJSON_CreateObject();
    stream strm;
    mstream_init(&strm);
    cJSON_AddNumberToObject(json, "turn", 1);
    json_write(json, &strm);
    strm.api->rewind(strm.handle);
    strm.api->readln(strm.handle, buf, sizeof(buf));
    CuAssertStrEquals(tc, "{", buf);
    strm.api->readln(strm.handle, buf, sizeof(buf));
    CuAssertStrEquals(tc, "\t\"turn\":\t1", buf);
    strm.api->readln(strm.handle, buf, sizeof(buf));
    CuAssertStrEquals(tc, "}", buf);
    cJSON_Delete(json);
    mstream_done(&strm);
}
Exemple #11
0
static void test_spellref(CuTest *tc)
{
    spellref *ref;
    spell *sp;
    test_setup();
    ref = spellref_create(NULL, "hodor");
    CuAssertPtrNotNull(tc, ref);
    CuAssertPtrEquals(tc, NULL, ref->sp);
    CuAssertStrEquals(tc, "hodor", ref->_name);
    CuAssertPtrEquals(tc, NULL, spellref_get(ref));
    CuAssertStrEquals(tc, "hodor", spellref_name(ref));
    sp = create_spell("hodor");
    CuAssertPtrNotNull(tc, sp);
    CuAssertPtrEquals(tc, sp, spellref_get(ref));
    spellref_free(ref);
    test_teardown();
}
Exemple #12
0
// -----------------------------------------------------------------------------
// Test: codeblock_execute() -- simple codeblock
// -----------------------------------------------------------------------------
void test_codeblock_execute(CuTest *tc)
{
    Codeblock* cb = codeblock_create();
    cb->ast       = cb_conststr_create("test");
    
    codeblock_execute(cb); // execute codeblock once
    
    CuAssertIntEquals(tc, CB_VT_STRING, cb_value_get_type(cb->result));
    CuAssertStrEquals(tc, "test",       cb_string_get(cb->result));
    
    codeblock_execute(cb); // execute a second time
    
    CuAssertIntEquals(tc, CB_VT_STRING, cb_value_get_type(cb->result));
    CuAssertStrEquals(tc, "test",       cb_string_get(cb->result));
    
    codeblock_free(cb);
}
Exemple #13
0
void Test_d_string_insert_printf(CuTest* tc) {
	char * test = "foo";

	DString * result = d_string_new(test);

	d_string_insert_printf(result, 2, "%dbar%d", 5, 7);
	CuAssertStrEquals(tc, "fo5bar7o", result->str);
	CuAssertIntEquals(tc, 8, result->currentStringLength);

	d_string_insert_printf(result, -1, "z", 5, 7);
	CuAssertStrEquals(tc, "fo5bar7oz", result->str);
	CuAssertIntEquals(tc, 9, result->currentStringLength);

	d_string_insert_printf(NULL, 0, NULL);

	d_string_free(result, true);
}
Exemple #14
0
void Test_d_string_prepend(CuTest* tc) {
	char * test = "foo";

	DString * result = d_string_new(test);

	d_string_prepend(result, "bar");
	CuAssertStrEquals(tc, "barfoo", result->str);
	CuAssertIntEquals(tc, 6, result->currentStringLength);

	d_string_prepend(result, NULL);
	CuAssertStrEquals(tc, "barfoo", result->str);
	CuAssertIntEquals(tc, 6, result->currentStringLength);

	d_string_prepend(NULL, "bar");

	d_string_free(result, true);
}
test_uri_normalize_2(CuTest *tc)
{
	char *expect = strdup("http://www.example.com/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = uri_normalize(&uri);
	CuAssertStrEquals(tc,*uri.uri_host,"www.example.com");
}
test_uri_norm_auth_4(CuTest *tc)
{
	char *expect = strdup("http://www.example.com:8080/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = uri_norm_auth(&uri);
	CuAssertStrEquals(tc,*uri.uri_port,"8080");
}
Exemple #17
0
void test_create_a_finite_automata(CuTest *tc)
{
    setup();
    CuAssertStrEquals(tc, "test", m->subject);
    CuAssertIntEquals(tc, -1, m->initial_state);
    CuAssertIntEquals(tc, NUMBER_STATES, m->nstates);
    teardown();
}
test_uri_normalize_1(CuTest *tc)
{
	char *expect = strdup("http://192.168.1.100:8080/test/func.cgi?x=y&z=j");
	uriobj_t uri;
	uri_parse(&uri, re, expect);
	int err = uri_normalize(&uri);
	CuAssertStrEquals(tc,*uri.uri_ip,"192.168.1.100");
}
Exemple #19
0
void Test_d_string_append_c(CuTest* tc) {
	char * test = "foo";

	DString * result = d_string_new(test);

	d_string_append_c(result, 'z');
	CuAssertStrEquals(tc, "fooz", result->str);
	CuAssertIntEquals(tc, 4, result->currentStringLength);

	d_string_append_c(result, 0);
	CuAssertStrEquals(tc, "fooz", result->str);
	CuAssertIntEquals(tc, 4, result->currentStringLength);

	d_string_append_c(NULL, 'f');

	d_string_free(result, true);
}
Exemple #20
0
void
test_grid_viewport_tree(CuTest *tc) {
    grid_context_t *gr = new_grid_context(100, 100);

    grid_viewport_t *apple = new_grid_default_viewport();
    grid_push_named_viewport(gr, "apple", apple);

    CuAssertTrue(tc, gr->root_node != gr->current_node);
    CuAssertStrEquals(tc, gr->current_node->name, "apple");
    CuAssertPtrEquals(tc, gr->root_node->child, gr->current_node);
    CuAssertPtrEquals(tc, gr->current_node->parent, gr->root_node);

    grid_viewport_t *banana = new_grid_default_viewport();
    grid_viewport_t *carrot = new_grid_default_viewport();
    grid_push_named_viewport(gr, "banana", banana);
    grid_up_viewport_1(gr);
    grid_push_named_viewport(gr, "carrot", carrot);

    CuAssertStrEquals(tc, "carrot", gr->current_node->name);
    CuAssertStrEquals(tc, "banana", gr->current_node->gege->name);
    CuAssertStrEquals(tc, "carrot", gr->current_node->gege->didi->name);
    CuAssertStrEquals(tc, "apple", gr->current_node->parent->name);

    bool result = grid_pop_viewport_1(gr);
    CuAssertTrue(tc, result);
    CuAssertStrEquals(tc, "apple", gr->current_node->name);
    CuAssertStrEquals(tc, "banana", gr->current_node->child->name);
    CuAssertPtrEquals(tc, NULL, gr->current_node->child->didi);

    int n = grid_down_viewport(gr, "durian");
    CuAssertIntEquals(tc, -1, n);
    CuAssertStrEquals(tc, "apple", gr->current_node->name);

    n = grid_down_viewport(gr, "banana");
    CuAssertIntEquals(tc, 1, n);
    CuAssertStrEquals(tc, "banana", gr->current_node->name);

    grid_push_named_viewport(gr, "carrot", carrot);
    n = grid_down_viewport(gr, "banana");
    CuAssertIntEquals(tc, -1, n);
    n = grid_seek_viewport(gr, "banana");
    CuAssertIntEquals(tc, 2, n);
    CuAssertStrEquals(tc, "banana", gr->current_node->name);

    free_grid_context(gr);
}
void Test_sh_tools_safe_name_04(CuTest *tc) {
  /* invalid and valid octal code */
  char* input = strdup("hello\\\n");
  char* actual = sh_tools_safe_name(input, 0);
  char* expected = "hello";
  CuAssertStrEquals(tc, expected, actual);

  input = strdup("hello\\100");
  actual = sh_tools_safe_name(input, 0);
  expected = "hello=40";
  CuAssertStrEquals(tc, expected, actual);

  input = strdup("h\\\"ello\\100a");
  actual = sh_tools_safe_name(input, 0);
  expected = "h=22ello=40a";
  CuAssertStrEquals(tc, expected, actual);
}
Exemple #22
0
static void test_group_readwrite(CuTest * tc)
{
    faction * f;
    group *g;
    ally *al;
    int i;
    gamedata data;
    storage store;

    test_cleanup();
    mstream_init(&data.strm);
    gamedata_init(&data, &store, RELEASE_VERSION);
    f = test_create_faction(0);
    new_group(f, "NW", 42);
    g = new_group(f, "Egoisten", 43);
    key_set(&g->attribs, 44);
    al = ally_add(&g->allies, f);
    al->status = HELP_GIVE;
    write_groups(&store, f);
    WRITE_INT(&store, 47);

    free_group(f->groups);
    free_group(g);
    f->groups = 0;
    data.strm.api->rewind(data.strm.handle);
    read_groups(&data, f);
    READ_INT(&store, &i);
    mstream_done(&data.strm);
    gamedata_done(&data);

    CuAssertIntEquals(tc, 47, i);
    CuAssertPtrNotNull(tc, f->groups);
    CuAssertIntEquals(tc, 42, f->groups->gid);
    CuAssertStrEquals(tc, "NW", f->groups->name);
    CuAssertPtrNotNull(tc, f->groups->next);
    CuAssertIntEquals(tc, 43, f->groups->next->gid);
    CuAssertStrEquals(tc, "Egoisten", f->groups->next->name);
    CuAssertPtrEquals(tc, 0, f->groups->allies);
    g = f->groups->next;
    CuAssertTrue(tc, key_get(g->attribs, 44));
    CuAssertPtrNotNull(tc, g->allies);
    CuAssertPtrEquals(tc, 0, g->allies->next);
    CuAssertPtrEquals(tc, f, g->allies->faction);
    CuAssertIntEquals(tc, HELP_GIVE, g->allies->status);
    test_cleanup();
}
Exemple #23
0
void test_user_groups_retrieves_users_groups(CuTest *tc)
{
    char **groups;
    setup();

    groups = user_get_groups("bob", "first");
    CuAssertPtrNotNull(tc, groups);
    CuAssertStrEquals(tc, "admin", groups[0]);
    CuAssertStrEquals(tc, "user", groups[1]);

    /* This assertion ensures that groups come from a single
     * animal.
     */
    CuAssertPtrEquals(tc, NULL, groups[2]);

    teardown();
}
void testSetUnion(CuTest *tc) {
	char* input1;
	char* input2;
	char* expected;
	set setU;

	input1 = strdup("");  input2=strdup("a c b");  expected = "a b c"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	input1 = strdup("a b c");  input2=strdup("");  expected = "a b c"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	input1 = strdup("a b c");  input2=NULL;  expected = NULL; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	input1 = NULL;  input2=strdup("c b a");  expected = NULL; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	// Boundary case - 9 members in result - should be OK
	input1 = strdup("i h g f p a z");  input2=strdup("i h g f e d");  expected = "a d e f g h i p z"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	// Boundary case - 10 members in result which is ON THE LIMIT, and therefore should return NULL
	input1 = strdup("i h g f p a z x");  input2=strdup("i h g f e d");  expected = NULL;
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	// Boundary case - 12 members in result which is OVER THE LIMIT, and therefore should return NULL
	input1 = strdup("i h g f p a z x");  input2=strdup("i h g f e d w y");  expected = NULL; //"a d e f g h i p w x y z"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

} //testSetUnion
Exemple #25
0
void check_tokens(CuTest *tc, token_t *head, char *expected[], int expected_len) {
	int i = 0;
	while (head) {
		CuAssertStrEquals(tc, expected[i], head->token);
		head = head->next;
		i++;
	}
	CuAssertIntEquals(tc, expected_len, i);
}
Exemple #26
0
static void testLookupByName(CuTest *tc) {
    struct netcf_if *nif;

    nif = ncf_lookup_by_name(ncf, "br0");
    CuAssertPtrNotNull(tc, nif);
    CuAssertStrEquals(tc, "br0", nif->name);
    ncf_if_free(nif);
    CuAssertIntEquals(tc, 1, ncf->ref);
}
Exemple #27
0
static void test_parse_maketemp(CuTest *tc) {
    char cmd[32];
    order *ord;
    struct locale * lang = get_or_create_locale("en");

    locale_setstring(lang, keyword(K_MAKE), "MAKE");
    locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
    locale_setstring(lang, "TEMP", "TEMP");
    init_locale(lang);

    ord = parse_order("MAKET herp", lang);
    CuAssertPtrNotNull(tc, ord);
    CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
    CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
    CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
    CuAssertStrEquals(tc, "herp", getstrtoken());
    free_order(ord);
}
Exemple #28
0
void Test_d_string_append(CuTest* tc) {
	char * test = "foo";

	DString * result = d_string_new(test);

	d_string_append(result, "bar");
	CuAssertStrEquals(tc, "foobar", result->str);

	d_string_append(result, "");
	CuAssertStrEquals(tc, "foobar", result->str);

	d_string_append(result, NULL);
	CuAssertStrEquals(tc, "foobar", result->str);

	d_string_append(NULL, "foo");

	d_string_free(result, true);
}
 void check(CuTest* tc, const TCHAR* input, const TCHAR* expected) {
   StandardTokenizer* tokenStream = new StandardTokenizer(new StringReader(input));
   GermanStemFilter filter(tokenStream, true);
   Token t;
   if (filter.next(&t) == NULL)
     CuFail(tc, _T("Token expected!"));
   CuAssertStrEquals(tc, _T(""), expected, t.termBuffer());
   filter.close();
 }
Exemple #30
0
void test_reverse1_to_reverse_the_string_itself(CuTest *tc)
{
    /*
     * The string block "str" is readonly on  C, so we must
     * create an "array" of chars with null char at end
     */
    char text1[] = { 'b', 'u', 't', '\0' };
    char text2[] = { 'd', 'o', '\0' };
    
    CuAssertStrEquals(tc, "but", text1);
    CuAssertStrEquals(tc, "do", text2);
    
    reverse1(text1);
    reverse1(text2);
    
    CuAssertStrEquals(tc, "tub", text1);
    CuAssertStrEquals(tc, "od", text2);
}