Example #1
0
File: FORM.C Project: LesInk/Test
T_formObjectID FormAddText(
        T_word16 x1,
        T_word16 y1,
        T_byte8 *data,
        T_byte8 *fontname,
        T_byte8 fcolor,
        T_byte8 bcolor,
        T_word32 idnum)
{
    T_word16 i;
    T_textID textID;

    DebugRoutine("FormAddText");
    DebugCheck(fontname!=NULL);
    DebugCheck(data!=NULL);

    for (i = 0; i < MAX_FORM_OBJECTS; i++) {
        /* find an empty slot */
        if (G_formObjectArray[i] == NULL ) {
            /* found one, create a new button */
            textID = TextCreate(x1, y1, data);
            TextSetFont(textID, fontname);
            TextSetColor(textID, fcolor, bcolor);
            /* now that a button has been created, make an objstruct for it */
            G_formObjectArray[i] = FormCreateObject(FORM_OBJECT_TEXT,
                    (T_formObjectID)textID, idnum);
            /* we made a new object struct, break from the loop */
            break;
        }
    }

    /* make sure we haven't exceeded any limits */
    DebugCheck(i!=MAX_FORM_OBJECTS);
    DebugEnd();
    /* return the ID for the object created */
    return (G_formObjectArray[i]);
}
Example #2
0
int
main(int argc, char **argv)
{
	Text a;
	struct text data;
	const char *abc = "abc";

	printf("\n--Text--\n");

	printf("init local stack object\n");
	TextInitEmptyString(&data);

	printf("destroy local stack object\n");
	data.destroy(&data);

	printf("\ncreate from string");
	isNotNull(a = TextCreate(abc));

	printf("length=%ld...%s\n", a->length(a), (size_t) a->length(a) == sizeof (abc)-1 ? "OK" : "FAIL");
	printf("content same as original...%s\n", memcmp(a->string(a), abc, sizeof (abc)) == 0 ? "OK" : "FAIL");

	printf("destroy a\n");
	a->destroy(a);

	printf("\nTextCompareIgnoreCase\n");
	TestCompareFunction(TextCompareIgnoreCase, TextCreate("a"), TextCreate("A"), 0);
	TestCompareFunction(TextCompareIgnoreCase, TextCreate("b"), TextCreate("A"), 1);
	TestCompareFunction(TextCompareIgnoreCase, TextCreate("a"), TextCreate("B"), -1);

	TestCompareFunction(TextCompareIgnoreCase, TextCreate("ab"), TextCreate("AB"), 0);
	TestCompareFunction(TextCompareIgnoreCase, TextCreate("ab"), TextCreate("A"), 1);
	TestCompareFunction(TextCompareIgnoreCase, TextCreate("a"), TextCreate("AB"), -1);

	TestCompareFunction(TextCompareIgnoreCase, TextCreate("ORDB.org"), TextCreate("ordborg"), -1);
	TestCompareFunction(TextCompareIgnoreCase, TextCreate("ORDB.org"), TextCreate("ordb.org"), 0);
	TestCompareFunction(TextCompareIgnoreCase, TextCreate("*****@*****.**"), TextCreate("*****@*****.**"), 0);

	printf("\nTextEndsWith\n");
	TestFunction(TextEndsWithIgnoreCase, TextCreate(""), TextCreate("ordb.org"), -1);
	TestFunction(TextEndsWithIgnoreCase, TextCreate(".org"), TextCreate("ordb.org"), -1);
	TestFunction(TextEndsWithIgnoreCase, TextCreate("ORDB.org"), TextCreate("ordb.org"), sizeof("ordb.org")-1);
	TestFunction(TextEndsWithIgnoreCase, TextCreate("*****@*****.**"), TextCreate("ordb.org"), sizeof("ordb.org")-1);

	printf("\nTextSplitOn\n");

	/* Empty string and empty delimeters. */
	TestTextSplit(TextCreate(""), TextCreate(""), 1, 1);		/* length=1 [] */
	TestTextSplit(TextCreate(""), TextCreate(""), 0, 0);		/* length=0 */

	/* Empty string. */
	TestTextSplit(TextCreate(""), TextCreate(","), 1, 1);		/* length=1 [] */
	TestTextSplit(TextCreate(""), TextCreate(","), 0, 0);		/* length=0 */

	/* Empty delimiters. */
	TestTextSplit(TextCreate("a,b,c"), TextCreate(""), 1, 1);		/* length=1 [a,b,c] */
	TestTextSplit(TextCreate("a,b,c"), TextCreate(""), 0, 1);		/* length=1 [a,b,c] */

	/* Assorted combinations of empty tokens. */
	TestTextSplit(TextCreate(","), TextCreate(","), 1, 2);		/* length=2 [][] */
	TestTextSplit(TextCreate(","), TextCreate(","), 0, 0);		/* length=0 */
	TestTextSplit(TextCreate("a,,"), TextCreate(","), 1, 3);		/* length=3 [a][][] */
	TestTextSplit(TextCreate("a,,"), TextCreate(","), 0, 1);		/* length=1 [a] */
	TestTextSplit(TextCreate(",b,"), TextCreate(","), 1, 3);		/* length=3 [][b][] */
	TestTextSplit(TextCreate(",b,"), TextCreate(","), 0, 1);		/* length=1 [b] */
	TestTextSplit(TextCreate(",,c"), TextCreate(","), 1, 3);		/* length=3 [][][c] */
	TestTextSplit(TextCreate(",,c"), TextCreate(","), 0, 1);		/* length=1 [c] */
	TestTextSplit(TextCreate("a,,c"), TextCreate(","), 1, 3);		/* length=3 [a][][c] */
	TestTextSplit(TextCreate("a,,c"), TextCreate(","), 0, 2);		/* length=2 [a][c] */
	TestTextSplit(TextCreate("a,b,c"), TextCreate(","), 1, 3);		/* length=3 [a][b][c] */
	TestTextSplit(TextCreate("a,b,c"), TextCreate(","), 0, 3);		/* length=3 [a][b][c] */

	/* Quoting of tokens. */
	TestTextSplit(TextCreate("a,b\\,c"), TextCreate(","), 1, 2);	/* length=2 [a][b,c] */
	TestTextSplit(TextCreate("a,b\\,c"), TextCreate(","), 0, 2);	/* length=2 [a][b,c] */
	TestTextSplit(TextCreate("a,'b,c'"), TextCreate(","), 1, 2);	/* length=2 [a][b,c] */
	TestTextSplit(TextCreate("a,'b,c'"), TextCreate(","), 0, 2);	/* length=2 [a][b,c] */
	TestTextSplit(TextCreate("\"a,b\",c"), TextCreate(","), 1, 2);	/* length=2 [a,b][c] */
	TestTextSplit(TextCreate("\"a,b\",c"), TextCreate(","), 0, 2);	/* length=2 [a,b][c] */
	TestTextSplit(TextCreate("a,'b,c'd,e"), TextCreate(","), 1, 3);	/* length=3 [a][b,cd][e] */
	TestTextSplit(TextCreate("a,'b,c'd,e"), TextCreate(","), 0, 3);	/* length=3 [a][b,cd][e] */
	TestTextSplit(TextCreate("a,'',e"), TextCreate(","), 1, 3);	/* length=3 [a][][e] */
	TestTextSplit(TextCreate("a,'',e"), TextCreate(","), 0, 3);	/* length=3 [a][][e] */
	TestTextSplit(TextCreate("a,b''d,e"), TextCreate(","), 1, 3);	/* length=3 [a][bd][e] */
	TestTextSplit(TextCreate("a,b''d,e"), TextCreate(","), 0, 3);	/* length=3 [a][bd][e] */

	printf("\n--DONE--\n");

	return 0;
}