Usermode - More hackery to get glib compiling
[tpg/acess2.git] / Usermode / Applications / gui_terminal_src / UTEST / TEST_vt100.c
1 /*
2  */
3
4 #include "test_common.h"
5 #include <string.h>
6 #include <display.h>
7
8 // === GLOBALS ===
9 void    (*gpTest_VT100_AddText)(size_t Length, const char *UTF8Text);
10 void    (*gpTest_VT100_SetTitle)(const char *Title);
11
12 // === CODE ===
13 int Test_VT100_Setup(void)
14 {
15         gpTest_VT100_AddText = NULL;
16         gpTest_VT100_SetTitle = NULL;
17         return 0;
18 }
19
20 int Test_VT100_int_Command(int MaxCalls, const char *Command)
21 {
22         const char *buf = Command;
23          int    len = strlen(Command);
24          int    nCalls = 0;
25         while( len > 0 )
26         {
27                 TEST_ASSERT_R(nCalls, <, MaxCalls);
28                 int rv = Term_HandleVT100(NULL, len, buf);
29                 if( rv < 0 )
30                         return buf - Command;
31                 TEST_ASSERT_R(rv, !=, 0);
32                 TEST_ASSERT_R(rv, <=, len);
33                 len -= rv;
34                 buf += rv;
35                 nCalls ++;
36         }
37         
38         return buf - Command;
39 }
40
41 void Test_VT100_TitleSet(void)
42 {
43         #define TITLE1  "Testing Title, quite long and complex ;;"
44         const char cmd_long_long[] = "\033]0;"TITLE1"\033\\";
45         #define TITLE2  "Another completely[]different title--"
46         const char cmd_long_st[] = "\033]0;"TITLE2"\x9c";
47         #define TITLE3  "12345678b sbuog egu nz vlj=+~`][]\033  "
48         const char cmd_long_bel[] = "\033]0;"TITLE3"\007";
49         const char *expected_title;
50
51          int    title_was_set=0, rv;
52         
53         void _settitle(const char *Title) {
54                 TEST_ASSERT_SR( Title, ==, expected_title );
55                 title_was_set = 1;
56         }
57         gpTest_VT100_SetTitle = _settitle;
58         
59         expected_title = TITLE1;
60         title_was_set = 0;
61         rv = Test_VT100_int_Command(10, cmd_long_long);
62         TEST_ASSERT_R(rv, ==, sizeof(cmd_long_long)-1);
63         TEST_ASSERT(title_was_set);
64         
65         expected_title = TITLE2;
66         title_was_set = 0;
67         rv = Test_VT100_int_Command(10, cmd_long_st);
68         TEST_ASSERT_R(rv, ==, sizeof(cmd_long_st)-1);
69         TEST_ASSERT(title_was_set);
70         
71         expected_title = TITLE3;
72         title_was_set = 0;
73         rv = Test_VT100_int_Command(10, cmd_long_bel);
74         TEST_ASSERT_R(rv, ==, sizeof(cmd_long_bel)-1);
75         TEST_ASSERT(title_was_set);
76 }
77
78 // === TESTS ===
79 tTEST   gaTests[] = {
80         {"VT100 TitleSet", NULL, Test_VT100_TitleSet, NULL}
81 };
82 int giNumTests = sizeof(gaTests)/sizeof(gaTests[0]);
83
84 // === Hooks ===
85 void    *gpTermStatePtr;
86 void *Display_GetTermState(tTerminal *Term) {
87         return gpTermStatePtr;
88 }
89 void Display_SetTermState(tTerminal *Term, void *State) {
90         gpTermStatePtr = State;
91 }
92
93 void Display_AddText(tTerminal *Term, size_t Length, const char *UTF8Text) {
94         TEST_ASSERT(gpTest_VT100_AddText);
95         gpTest_VT100_AddText(Length, UTF8Text);
96 }
97 void Display_Newline(tTerminal *Term, bool bCarriageReturn) {
98         //if( gpTest_VT100_Newline )
99         //      gpTest_VT100_Newline(Term, bCarriageReturn);
100 }
101 void Display_SetScrollArea(tTerminal *Term, int Start, int Count) {
102         //if( gpTest_VT100_SetScrollArea )
103         //      gpTest_VT100_SetScrollArea(Term, Start, Count);
104 }
105 void Display_ScrollDown(tTerminal *Term, int Count) {
106 }
107 void Display_SetCursor(tTerminal *Term, int Row, int Col) {
108 }
109 void Display_MoveCursor(tTerminal *Term, int RelRow, int RelCol) {
110 }
111 void Display_SaveCursor(tTerminal *Term) {
112 }
113 void Display_RestoreCursor(tTerminal *Term) {
114 }
115 void Display_ClearLine(tTerminal *Term, int Dir) {      // 0: All, 1: Forward, -1: Reverse
116 }
117 void Display_ClearLines(tTerminal *Term, int Dir) {     // 0: All, 1: Forward, -1: Reverse
118 }
119 void Display_ResetAttributes(tTerminal *Term) {
120 }
121 void Display_SetForeground(tTerminal *Term, uint32_t RGB) {
122 }
123 void Display_SetBackground(tTerminal *Term, uint32_t RGB) {
124 }
125 void Display_Flush(tTerminal *Term) {
126 }
127 void Display_ShowAltBuffer(tTerminal *Term, bool AltBufEnabled) {
128 }
129 void Display_SetTitle(tTerminal *Term, const char *Title) {
130         TEST_ASSERT(gpTest_VT100_SetTitle);
131         gpTest_VT100_SetTitle(Title);
132 }

UCC git Repository :: git.ucc.asn.au