gwenhywfar 5.12.0
fox16/libtest.cpp
Go to the documentation of this file.
1
2#ifdef HAVE_CONFIG_H
3# include <config.h>
4#endif
5
6#ifdef OS_WIN32
7# include <windows.h>
8# define sleep(x) Sleep(x)
9#endif
10
11
12#undef BUILDING_FOX16_GUI
13
14
15#include <gwen-gui-fox16/fox16_gui.hpp>
16#include "fox16_htmlctx.hpp"
17#include "fox16_htmllabel.hpp"
18#include "fox16_htmltext.hpp"
19
22
23#include <gwenhywfar/gwenhywfar.h>
24#include <gwenhywfar/debug.h>
25#include <gwenhywfar/passwdstore.h>
26
27#include <unistd.h>
28
29
30
31int test1(int argc, char **argv) {
32 FXApp a("libtest","Martin Preuss");
33 FOX16_Gui *gui;
34 //int rv;
35 const char testString[]=
36#if 0
37# if 0
38 "This is <b>a</b> test. "
39 "And this, is the second line: followed by something else."
40 "<table>"
41 " <tr>"
42 " <th>header1</th>"
43 " <th>header2</th>"
44 " </tr>"
45 " <tr>"
46 " <td>data1</td>"
47 " <td>data2</td>"
48 " </tr>"
49 "</table>"
50 "And this is after the table.<br>"
51 "and this <font color=\"red\">one</font> is red.";
52# else
53 "This is before right"
54 "<right>RIGHT</right>"
55 "and this after right.";
56# endif
57#else
58 "word";
59#endif
60
61 a.init(argc,argv);
62 a.create();
63
64 gui=new FOX16_Gui(&a);
66
67 FOX16_HtmlCtx ctx(0);
68 ctx.setText(testString);
69 //rv=ctx.layout(300, 1024);
70 //fprintf(stderr, "Result of layout: %d\n", rv);
71 ctx.dump();
72
74 delete gui;
75
76 return 0;
77}
78
79
80
81
82int test2(int argc, char **argv) {
83 FXApp application("libtest","Martin Preuss");
84 FOX16_Gui *gui;
85 int rv;
86 uint32_t id1;
87 uint32_t id2;
88 uint64_t i1;
89 uint64_t i2;
90
91 application.init(argc,argv);
92
93 application.create();
94
95 gui=new FOX16_Gui(&application);
97
101 "Progress-Title",
102 "<html>"
103 "<p><b>This</b> is an example <i>text</i>..</p>"
104 "<p>As you can see <font color=red>colors</font> can "
105 "be used.</p>"
106 "</html>",
107 15,
108 0);
109 for (i1=1; i1<=15; i1++) {
111 "Step %d: This is a another step in the test of progress widgets",
112 (int) i1);
116 "2nd progress",
117 "Starting 2nd progress...",
118 5,
119 id1);
120 for (i2=1; i2<=3; i2++) {
121 sleep(1);
122 fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
123 rv=GWEN_Gui_ProgressAdvance(id2, i2);
124 if (rv==GWEN_ERROR_USER_ABORTED) {
125 fprintf(stderr, "Aborted by user\n");
126 break;
127 }
128 }
130
131 rv=GWEN_Gui_ProgressAdvance(id1, i1);
132 if (rv==GWEN_ERROR_USER_ABORTED) {
133 fprintf(stderr, "Aborted by user\n");
134 break;
135 }
136 }
137
139
140 return 0;
141}
142
143
144
145int test3(int argc, char **argv) {
146 FXApp a("libtest","Martin Preuss");
147 FOX16_Gui *gui;
148 FXDialogBox *dbox;
149 FXVerticalFrame *vf;
150 const char testString[]=
151#if 1
152 "<h1>Title</h1>"
153 "<h2>Subtitle</h2>"
154 "This is <b>a</b> test. "
155 "And this, is the second line: followed by something else."
156 "<right>This should be right aligned</right>"
157 "<table>"
158 " <tr>"
159 " <th>header1</th>"
160 " <th>header2</th>"
161 " </tr>"
162 " <tr>"
163 " <td>data1</td>"
164 " <td>this is longer data (data2)</td>"
165 " </tr>"
166 "</table>"
167 "And this is after the table.<br>"
168 "and this <font color=\"red\">one</font> is red.";
169#else
170 "This is before right"
171 "<right>Right</right>"
172 "and this after right.";
173#endif
174 a.init(argc,argv);
175 a.create();
176
177 gui=new FOX16_Gui(&a);
179
180 dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
181 vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
182 0, 0, 0, 0, 1, 1, 1, 1);
183 new FOX16_HtmlLabel(vf, FXString(testString), LAYOUT_FILL_X|LAYOUT_FILL_Y);
184 new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
185 new FXLabel(vf, "Normal Testlabel");
186
187 dbox->create();
188 dbox->resize(300, 200);
189 dbox->show();
190 a.runModalFor(dbox);
191
192 return 0;
193}
194
195
196
197int test4(int argc, char **argv) {
198 FXApp application("libtest","Martin Preuss");
199 FOX16_Gui *gui;
200 int rv;
201 uint32_t id1;
202 uint32_t id2;
203 uint64_t i1;
204 uint64_t i2;
205
206 application.init(argc,argv);
207
208 application.create();
209
210 gui=new FOX16_Gui(&application);
212
216 "Progress-Title",
217 "<html>"
218 "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
219 "</html>",
220 10,
221 0);
222 for (i1=1; i1<=10; i1++) {
223 char numbuf[128];
224
225 snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
230 "2nd progress",
231 "Starting 2nd progress...",
232 10,
233 id1);
234 for (i2=1; i2<=10; i2++) {
235 sleep(1);
236 fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
237 rv=GWEN_Gui_ProgressAdvance(id2, i2);
238 if (rv==GWEN_ERROR_USER_ABORTED) {
239 fprintf(stderr, "Aborted by user\n");
240 break;
241 }
242 }
244
245 rv=GWEN_Gui_ProgressAdvance(id1, i1);
246 if (rv==GWEN_ERROR_USER_ABORTED) {
247 fprintf(stderr, "Aborted by user\n");
248 break;
249 }
250 }
251
253
254 return 0;
255}
256
257
258
259int test5(int argc, char **argv) {
260 FXApp a("libtest","Martin Preuss");
261 FOX16_Gui *gui;
262 FXDialogBox *dbox;
263 FXVerticalFrame *vf;
264 const char testString[]=
265#if 1
266 "<h1>Test5</h1>"
267 "<h2>Subtitle</h2>"
268 "This is <b>a</b> test. "
269 "And this, is the second line: followed by something else."
270 "<right>This should be right aligned</right>"
271 "<table>"
272 " <tr>"
273 " <th>header1</th>"
274 " <th>header2</th>"
275 " </tr>"
276 " <tr>"
277 " <td>data1</td>"
278 " <td>this is longer data (data2)</td>"
279 " </tr>"
280 "</table>"
281 "And this is after the table.<br>"
282 "and this <font color=\"red\">one</font> is red.";
283#else
284 "This is before right"
285 "<right>Right</right>"
286 "and this after right.";
287#endif
288 a.init(argc,argv);
289 a.create();
290
291 gui=new FOX16_Gui(&a);
293
294 dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
295 vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
296 0, 0, 0, 0, 1, 1, 1, 1);
297 new FOX16_HtmlText(vf, FXString(testString),
298 LAYOUT_FILL_X|LAYOUT_FILL_Y |
299 HSCROLLING_OFF | VSCROLLER_ALWAYS);
300 new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
301 new FXLabel(vf, "Normal Testlabel");
302
303 dbox->create();
304 dbox->resize(300, 200);
305 dbox->show();
306 a.runModalFor(dbox);
307
308 return 0;
309}
310
311
312
313int test6(int argc, char **argv) {
314 FXApp application("libtest","Martin Preuss");
315 FOX16_Gui *gui;
316 int rv;
317 uint32_t id1;
318 uint32_t id2;
319 uint64_t i1;
320 uint64_t i2;
321
322 application.init(argc,argv);
323
324 application.create();
325
326 gui=new FOX16_Gui(&application);
328
332 "Progress-Title",
333 "<html>"
334 "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
335 "</html>",
336 10,
337 0);
338 for (i1=1; i1<=20; i1++) {
339 char numbuf[128];
340
341 snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
346 "2nd progress",
347 "Starting 2nd progress...",
348 5,
349 id1);
350 for (i2=1; i2<=5; i2++) {
351 sleep(1);
352 fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
353 GWEN_Gui_ProgressLog(id2, GWEN_LoggerLevel_Notice, "Advancing...");
354 rv=GWEN_Gui_ProgressAdvance(id2, i2);
355 if (rv==GWEN_ERROR_USER_ABORTED) {
356 fprintf(stderr, "Aborted by user\n");
357 break;
358 }
359 }
361
362 rv=GWEN_Gui_ProgressAdvance(id1, i1);
363 if (rv==GWEN_ERROR_USER_ABORTED) {
364 fprintf(stderr, "Aborted by user\n");
365 break;
366 }
367 }
368
370
371 return 0;
372}
373
374
375
376int test7(int argc, char **argv) {
377 FXApp application("libtest","Martin Preuss");
378 FOX16_Gui *gui;
379 char buffer[65];
380
381 application.init(argc,argv);
382
383 application.create();
384
385 gui=new FOX16_Gui(&application);
387
389 "This is the Title",
390 "<html>This is the text.</html>This is ASCII",
391 buffer,
392 1,
393 sizeof(buffer)-1,
394 0);
395
396
397 return 0;
398}
399
400
401
402int test8(int argc, char **argv) {
403 FXApp application("libtest","Martin Preuss");
404 FOX16_Gui *gui;
405 int rv;
406 GWEN_DIALOG *dlg;
407
408 application.init(argc,argv);
409
410 application.create();
411
412 gui=new FOX16_Gui(&application);
414
415
418
419 dlg=Dlg_Test1_new();
420 if (dlg==NULL) {
421 fprintf(stderr, "Could not create dialog.\n");
422 return 2;
423 }
424
425 rv=GWEN_Gui_ExecDialog(dlg, 0);
426 fprintf(stderr, "Result: %d\n", rv);
427
428 return 0;
429}
430
431
432
433int test9(int argc, char **argv) {
434 FXApp application("libtest","Martin Preuss");
435 FOX16_Gui *gui;
436 int rv;
437 GWEN_DIALOG *dlg;
438
439 application.init(argc,argv);
440
441 application.create();
442
443 gui=new FOX16_Gui(&application);
445
446
449
450 dlg=Dlg_Test2_new();
451 if (dlg==NULL) {
452 fprintf(stderr, "Could not create dialog.\n");
453 return 2;
454 }
455
456 rv=GWEN_Gui_ExecDialog(dlg, 0);
457 fprintf(stderr, "Result: %d\n", rv);
458
459 return 0;
460}
461
462
463
464int test10(int argc, char **argv) {
465 FXApp application("libtest","Martin Preuss");
466 FOX16_Gui *gui;
467 int rv;
469 GWEN_DB_NODE *dbPasswords;
470 const char *token;
471 const char *epw;
472 char pw[256];
473
474 if (argc<4) {
475 DBG_ERROR(0, "Expected token and secret");
476 return 1;
477 }
478 token=argv[2];
479 epw=argv[3];
480
481 application.init(argc,argv);
482
483 application.create();
484
485 gui=new FOX16_Gui(&application);
487
488 sto=GWEN_PasswordStore_new("/tmp/pwstore.pw");
489 dbPasswords=GWEN_DB_Group_new("TempPasswords");
490
491 gui->setPasswordStore(sto);
492 gui->setPasswordDb(dbPasswords, 0);
493
494
497
498 rv=GWEN_Gui_GetPassword(0, token, "Get Password", "Please enter password 1", pw, 4, sizeof(pw)-1,
500 if (rv<0) {
501 DBG_ERROR(0, "Error getting password: %d", rv);
502 return 2;
503 }
504 if (strcmp(epw, pw)!=0) {
505 DBG_ERROR(0, "Bad password for token [%s], expected [%s], got [%s].", token, epw, pw);
506 return 2;
507 }
508
509#if 0
510 dlg=Dlg_Test2_new();
511 if (dlg==NULL) {
512 fprintf(stderr, "Could not create dialog.\n");
513 return 2;
514 }
515
516 rv=GWEN_Gui_ExecDialog(dlg, 0);
517 fprintf(stderr, "Result: %d\n", rv);
518#endif
519
520 return 0;
521}
522
523
524
525int test11(int argc, char **argv) {
526 FXApp application("libtest","Martin Preuss");
527 FOX16_Gui *gui;
528 char buffer[65];
529
530 application.init(argc,argv);
531
532 application.create();
533
534 gui=new FOX16_Gui(&application);
536
538 "This is the Title",
539 "<html>This is quite a long HTML text. This is the second sentence, which is a bit longer "
540 "than the first one.<br>In any case this sentence should begin on its own line</html>"
541
542 "This is quite a long HTML text. This is the second sentence, which is a bit longer "
543 "than the first one.\nIn any case this sentence should begin on its own line.",
544 buffer,
545 1,
546 sizeof(buffer)-1,
547 0);
548
549
550 return 0;
551}
552
553
554
555int test12(int argc, char **argv) {
556 FXApp application("libtest","Martin Preuss");
557 FOX16_Gui *gui;
558 char buffer[65];
559
560 application.init(argc,argv);
561
562 application.create();
563
564 gui=new FOX16_Gui(&application);
566
568 "This is the Title",
569 "<html><b>This</b> is quite a long HTML text. This is the second sentence, which is a bit longer "
570 "than the first one.<br>In any case this sentence should begin on its own line.</html>",
571 buffer,
572 1,
573 sizeof(buffer)-1,
574 0);
575
576
577 return 0;
578}
579
580
581
582
583int main(int argc, char **argv) {
584 GWEN_Init();
587
588 if (argc>1) {
589 if (strcasecmp(argv[1], "1")==0)
590 return test1(argc, argv);
591 else if (strcasecmp(argv[1], "2")==0)
592 return test2(argc, argv);
593 else if (strcasecmp(argv[1], "3")==0)
594 return test3(argc, argv);
595 else if (strcasecmp(argv[1], "4")==0)
596 return test4(argc, argv);
597 else if (strcasecmp(argv[1], "5")==0)
598 return test5(argc, argv);
599 else if (strcasecmp(argv[1], "6")==0)
600 return test6(argc, argv);
601 else if (strcasecmp(argv[1], "7")==0)
602 return test7(argc, argv);
603 else if (strcasecmp(argv[1], "8")==0)
604 return test8(argc, argv);
605 else if (strcasecmp(argv[1], "9")==0)
606 return test9(argc, argv);
607 else if (strcasecmp(argv[1], "10")==0)
608 return test10(argc, argv);
609 else if (strcasecmp(argv[1], "11")==0)
610 return test11(argc, argv);
611 else if (strcasecmp(argv[1], "12")==0)
612 return test12(argc, argv);
613 }
614 else
615 return test7(argc, argv);
616}
617
618
619
#define NULL
Definition binreloc.c:300
GWEN_GUI * getCInterface()
Definition cppgui.cpp:373
void setPasswordStore(GWEN_PASSWD_STORE *sto)
Definition cppgui.cpp:367
void setPasswordDb(GWEN_DB_NODE *dbPasswords, int persistent)
Definition cppgui.cpp:361
void setText(const char *s)
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition db.c:173
struct GWEN_DB_NODE GWEN_DB_NODE
Definition db.h:228
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
struct GWEN_DIALOG GWEN_DIALOG
Definition dialog.h:54
GWEN_DIALOG * Dlg_Test2_new()
Definition dlg_test2.c:94
GWEN_DIALOG * Dlg_Test1_new()
Definition dlg_test.c:269
#define GWEN_ERROR_USER_ABORTED
Definition error.h:65
int test8(int argc, char **argv)
int test12(int argc, char **argv)
int test11(int argc, char **argv)
int main(int argc, char **argv)
int test3(int argc, char **argv)
int test5(int argc, char **argv)
int test2(int argc, char **argv)
int test4(int argc, char **argv)
int test10(int argc, char **argv)
int test6(int argc, char **argv)
int test9(int argc, char **argv)
int test7(int argc, char **argv)
void GWEN_Gui_SetGui(GWEN_GUI *gui)
Definition gui.c:170
GWENHYWFAR_API int GWEN_Gui_ExecDialog(GWEN_DIALOG *dlg, uint32_t guiid)
GWENHYWFAR_API int GWEN_Gui_InputBox(uint32_t flags, const char *title, const char *text, char *buffer, int minLen, int maxLen, uint32_t guiid)
#define GWEN_GUI_PROGRESS_DELAY
Definition gui.h:192
#define GWEN_GUI_PROGRESS_KEEP_OPEN
Definition gui.h:198
@ GWEN_Gui_PasswordMethod_Text
Definition gui.h:166
GWENHYWFAR_API uint32_t GWEN_Gui_ProgressStart(uint32_t progressFlags, const char *title, const char *text, uint64_t total, uint32_t guiid)
GWENHYWFAR_API int GWEN_Gui_ProgressEnd(uint32_t id)
#define GWEN_GUI_INPUT_FLAGS_SHOW
Definition gui.h:213
GWENHYWFAR_API int GWEN_Gui_GetPassword(uint32_t flags, const char *token, const char *title, const char *text, char *buffer, int minLen, int maxLen, GWEN_GUI_PASSWORD_METHOD methodId, GWEN_DB_NODE *methodParams, uint32_t guiid)
Definition gui_passwd.c:346
GWENHYWFAR_API int GWEN_Gui_ProgressLog(uint32_t id, GWEN_LOGGER_LEVEL level, const char *text)
#define GWEN_GUI_PROGRESS_SHOW_ABORT
Definition gui.h:194
#define GWEN_GUI_PROGRESS_SHOW_LOG
Definition gui.h:193
GWENHYWFAR_API int GWEN_Gui_ProgressLog2(uint32_t id, GWEN_LOGGER_LEVEL level, const char *text,...)
GWENHYWFAR_API int GWEN_Gui_ProgressAdvance(uint32_t id, uint32_t progress)
int GWEN_Init(void)
Definition gwenhywfar.c:92
int test1()
Definition libtest.m:63
void GWEN_Logger_SetLevel(const char *logDomain, GWEN_LOGGER_LEVEL l)
Definition logger.c:627
#define GWEN_LOGDOMAIN
Definition logger.h:35
@ GWEN_LoggerLevel_Notice
Definition logger.h:70
@ GWEN_LoggerLevel_Debug
Definition logger.h:72
@ GWEN_LoggerLevel_Verbous
Definition logger.h:73
@ GWEN_LoggerLevel_Info
Definition logger.h:71
GWEN_PASSWD_STORE * GWEN_PasswordStore_new(const char *fname)
Definition passwdstore.c:46
struct GWEN_PASSWD_STORE GWEN_PASSWD_STORE
Definition passwdstore.h:37