gwenhywfar 5.14.1
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 GWEN_DIALOG *dlg;
35 int rv;
36
37 rv=GWEN_Init();
38 if (rv) {
39 DBG_ERROR_ERR(0, rv);
40 return 2;
41 }
42
44
45 a.init(argc,argv);
46 a.create();
47
48 gui=new FOX16_Gui(&a);
50
51 dlg=Dlg_Test1_new();
52 if (dlg==NULL) {
53 fprintf(stderr, "Could not create dialog.\n");
54 return 2;
55 }
56
57 rv=GWEN_Gui_ExecDialog(dlg, 0);
58 fprintf(stderr, "Result: %d\n", rv);
59
60
62 delete gui;
63
64 return 0;
65}
66
67
68
69
70int test2(int argc, char **argv) {
71 FXApp application("libtest","Martin Preuss");
72 FOX16_Gui *gui;
73 int rv;
74 uint32_t id1;
75 uint32_t id2;
76 uint64_t i1;
77 uint64_t i2;
78
79 application.init(argc,argv);
80
81 application.create();
82
83 gui=new FOX16_Gui(&application);
85
89 "Progress-Title",
90 "<html>"
91 "<p><b>This</b> is an example <i>text</i>..</p>"
92 "<p>As you can see <font color=red>colors</font> can "
93 "be used.</p>"
94 "</html>",
95 15,
96 0);
97 for (i1=1; i1<=15; i1++) {
99 "Step %d: This is a another step in the test of progress widgets",
100 (int) i1);
104 "2nd progress",
105 "Starting 2nd progress...",
106 5,
107 id1);
108 for (i2=1; i2<=3; i2++) {
109 sleep(1);
110 fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
111 rv=GWEN_Gui_ProgressAdvance(id2, i2);
112 if (rv==GWEN_ERROR_USER_ABORTED) {
113 fprintf(stderr, "Aborted by user\n");
114 break;
115 }
116 }
118
119 rv=GWEN_Gui_ProgressAdvance(id1, i1);
120 if (rv==GWEN_ERROR_USER_ABORTED) {
121 fprintf(stderr, "Aborted by user\n");
122 break;
123 }
124 }
125
127
128 return 0;
129}
130
131
132
133int test3(int argc, char **argv) {
134 FXApp a("libtest","Martin Preuss");
135 FOX16_Gui *gui;
136 FXDialogBox *dbox;
137 FXVerticalFrame *vf;
138 const char testString[]=
139#if 1
140 "<h1>Title</h1>"
141 "<h2>Subtitle</h2>"
142 "This is <b>a</b> test. "
143 "And this, is the second line: followed by something else."
144 "<right>This should be right aligned</right>"
145 "<table>"
146 " <tr>"
147 " <th>header1</th>"
148 " <th>header2</th>"
149 " </tr>"
150 " <tr>"
151 " <td>data1</td>"
152 " <td>this is longer data (data2)</td>"
153 " </tr>"
154 "</table>"
155 "And this is after the table.<br>"
156 "and this <font color=\"red\">one</font> is red.";
157#else
158 "This is before right"
159 "<right>Right</right>"
160 "and this after right.";
161#endif
162 a.init(argc,argv);
163 a.create();
164
165 gui=new FOX16_Gui(&a);
167
168 dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
169 vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
170 0, 0, 0, 0, 1, 1, 1, 1);
171 new FOX16_HtmlLabel(vf, FXString(testString), LAYOUT_FILL_X|LAYOUT_FILL_Y);
172 new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
173 new FXLabel(vf, "Normal Testlabel");
174
175 dbox->create();
176 dbox->resize(300, 200);
177 dbox->show();
178 a.runModalFor(dbox);
179
180 return 0;
181}
182
183
184
185int test4(int argc, char **argv) {
186 FXApp application("libtest","Martin Preuss");
187 FOX16_Gui *gui;
188 int rv;
189 uint32_t id1;
190 uint32_t id2;
191 uint64_t i1;
192 uint64_t i2;
193
194 application.init(argc,argv);
195
196 application.create();
197
198 gui=new FOX16_Gui(&application);
200
204 "Progress-Title",
205 "<html>"
206 "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
207 "</html>",
208 10,
209 0);
210 for (i1=1; i1<=10; i1++) {
211 char numbuf[128];
212
213 snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
218 "2nd progress",
219 "Starting 2nd progress...",
220 10,
221 id1);
222 for (i2=1; i2<=10; i2++) {
223 sleep(1);
224 fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
225 rv=GWEN_Gui_ProgressAdvance(id2, i2);
226 if (rv==GWEN_ERROR_USER_ABORTED) {
227 fprintf(stderr, "Aborted by user\n");
228 break;
229 }
230 }
232
233 rv=GWEN_Gui_ProgressAdvance(id1, i1);
234 if (rv==GWEN_ERROR_USER_ABORTED) {
235 fprintf(stderr, "Aborted by user\n");
236 break;
237 }
238 }
239
241
242 return 0;
243}
244
245
246
247int test5(int argc, char **argv) {
248 FXApp a("libtest","Martin Preuss");
249 FOX16_Gui *gui;
250 FXDialogBox *dbox;
251 FXVerticalFrame *vf;
252 const char testString[]=
253#if 1
254 "<h1>Test5</h1>"
255 "<h2>Subtitle</h2>"
256 "This is <b>a</b> test. "
257 "And this, is the second line: followed by something else."
258 "<right>This should be right aligned</right>"
259 "<table>"
260 " <tr>"
261 " <th>header1</th>"
262 " <th>header2</th>"
263 " </tr>"
264 " <tr>"
265 " <td>data1</td>"
266 " <td>this is longer data (data2)</td>"
267 " </tr>"
268 "</table>"
269 "And this is after the table.<br>"
270 "and this <font color=\"red\">one</font> is red.";
271#else
272 "This is before right"
273 "<right>Right</right>"
274 "and this after right.";
275#endif
276 a.init(argc,argv);
277 a.create();
278
279 gui=new FOX16_Gui(&a);
281
282 dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
283 vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
284 0, 0, 0, 0, 1, 1, 1, 1);
285 new FOX16_HtmlText(vf, FXString(testString),
286 LAYOUT_FILL_X|LAYOUT_FILL_Y |
287 HSCROLLING_OFF | VSCROLLER_ALWAYS);
288 new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
289 new FXLabel(vf, "Normal Testlabel");
290
291 dbox->create();
292 dbox->resize(300, 200);
293 dbox->show();
294 a.runModalFor(dbox);
295
296 return 0;
297}
298
299
300
301int test6(int argc, char **argv) {
302 FXApp application("libtest","Martin Preuss");
303 FOX16_Gui *gui;
304 int rv;
305 uint32_t id1;
306 uint32_t id2;
307 uint64_t i1;
308 uint64_t i2;
309
310 application.init(argc,argv);
311
312 application.create();
313
314 gui=new FOX16_Gui(&application);
316
320 "Progress-Title",
321 "<html>"
322 "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
323 "</html>",
324 10,
325 0);
326 for (i1=1; i1<=20; i1++) {
327 char numbuf[128];
328
329 snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
334 "2nd progress",
335 "Starting 2nd progress...",
336 5,
337 id1);
338 for (i2=1; i2<=5; i2++) {
339 sleep(1);
340 fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
341 GWEN_Gui_ProgressLog(id2, GWEN_LoggerLevel_Notice, "Advancing...");
342 rv=GWEN_Gui_ProgressAdvance(id2, i2);
343 if (rv==GWEN_ERROR_USER_ABORTED) {
344 fprintf(stderr, "Aborted by user\n");
345 break;
346 }
347 }
349
350 rv=GWEN_Gui_ProgressAdvance(id1, i1);
351 if (rv==GWEN_ERROR_USER_ABORTED) {
352 fprintf(stderr, "Aborted by user\n");
353 break;
354 }
355 }
356
358
359 return 0;
360}
361
362
363
364int test7(int argc, char **argv) {
365 FXApp application("libtest","Martin Preuss");
366 FOX16_Gui *gui;
367 char buffer[65];
368
369 application.init(argc,argv);
370
371 application.create();
372
373 gui=new FOX16_Gui(&application);
375
377 "This is the Title",
378 "<html>This is the text.</html>This is ASCII",
379 buffer,
380 1,
381 sizeof(buffer)-1,
382 0);
383
384
385 return 0;
386}
387
388
389
390int test8(int argc, char **argv) {
391 FXApp application("libtest","Martin Preuss");
392 FOX16_Gui *gui;
393 int rv;
394 GWEN_DIALOG *dlg;
395
396 application.init(argc,argv);
397
398 application.create();
399
400 gui=new FOX16_Gui(&application);
402
403
406
407 dlg=Dlg_Test1_new();
408 if (dlg==NULL) {
409 fprintf(stderr, "Could not create dialog.\n");
410 return 2;
411 }
412
413 rv=GWEN_Gui_ExecDialog(dlg, 0);
414 fprintf(stderr, "Result: %d\n", rv);
415
416 return 0;
417}
418
419
420
421int test9(int argc, char **argv) {
422 FXApp application("libtest","Martin Preuss");
423 FOX16_Gui *gui;
424 int rv;
425 GWEN_DIALOG *dlg;
426
427 application.init(argc,argv);
428
429 application.create();
430
431 gui=new FOX16_Gui(&application);
433
434
437
438 dlg=Dlg_Test2_new();
439 if (dlg==NULL) {
440 fprintf(stderr, "Could not create dialog.\n");
441 return 2;
442 }
443
444 rv=GWEN_Gui_ExecDialog(dlg, 0);
445 fprintf(stderr, "Result: %d\n", rv);
446
447 return 0;
448}
449
450
451
452int test10(int argc, char **argv) {
453 FXApp application("libtest","Martin Preuss");
454 FOX16_Gui *gui;
455 int rv;
457 GWEN_DB_NODE *dbPasswords;
458 const char *token;
459 const char *epw;
460 char pw[256];
461
462 if (argc<4) {
463 DBG_ERROR(0, "Expected token and secret");
464 return 1;
465 }
466 token=argv[2];
467 epw=argv[3];
468
469 application.init(argc,argv);
470
471 application.create();
472
473 gui=new FOX16_Gui(&application);
475
476 sto=GWEN_PasswordStore_new("/tmp/pwstore.pw");
477 dbPasswords=GWEN_DB_Group_new("TempPasswords");
478
479 gui->setPasswordStore(sto);
480 gui->setPasswordDb(dbPasswords, 0);
481
482
485
486 rv=GWEN_Gui_GetPassword(0, token, "Get Password", "Please enter password 1", pw, 4, sizeof(pw)-1,
488 if (rv<0) {
489 DBG_ERROR(0, "Error getting password: %d", rv);
490 return 2;
491 }
492 if (strcmp(epw, pw)!=0) {
493 DBG_ERROR(0, "Bad password for token [%s], expected [%s], got [%s].", token, epw, pw);
494 return 2;
495 }
496
497#if 0
498 dlg=Dlg_Test2_new();
499 if (dlg==NULL) {
500 fprintf(stderr, "Could not create dialog.\n");
501 return 2;
502 }
503
504 rv=GWEN_Gui_ExecDialog(dlg, 0);
505 fprintf(stderr, "Result: %d\n", rv);
506#endif
507
508 return 0;
509}
510
511
512
513int test11(int argc, char **argv) {
514 FXApp application("libtest","Martin Preuss");
515 FOX16_Gui *gui;
516 char buffer[65];
517
518 application.init(argc,argv);
519
520 application.create();
521
522 gui=new FOX16_Gui(&application);
524
526 "This is the Title",
527 "<html>This is quite a long HTML text. This is the second sentence, which is a bit longer "
528 "than the first one.<br>In any case this sentence should begin on its own line</html>"
529
530 "This is quite a long HTML text. This is the second sentence, which is a bit longer "
531 "than the first one.\nIn any case this sentence should begin on its own line.",
532 buffer,
533 1,
534 sizeof(buffer)-1,
535 0);
536
537
538 return 0;
539}
540
541
542
543int test12(int argc, char **argv) {
544 FXApp application("libtest","Martin Preuss");
545 FOX16_Gui *gui;
546 char buffer[65];
547
548 application.init(argc,argv);
549
550 application.create();
551
552 gui=new FOX16_Gui(&application);
554
556 "This is the Title",
557 "<html><b>This</b> is quite a long HTML text. This is the second sentence, which is a bit longer "
558 "than the first one.<br>In any case this sentence should begin on its own line.</html>",
559 buffer,
560 1,
561 sizeof(buffer)-1,
562 0);
563
564
565 return 0;
566}
567
568
569
570
571int main(int argc, char **argv) {
572 GWEN_Init();
575
576 if (argc>1) {
577 if (strcasecmp(argv[1], "1")==0)
578 return test1(argc, argv);
579 else if (strcasecmp(argv[1], "2")==0)
580 return test2(argc, argv);
581 else if (strcasecmp(argv[1], "3")==0)
582 return test3(argc, argv);
583 else if (strcasecmp(argv[1], "4")==0)
584 return test4(argc, argv);
585 else if (strcasecmp(argv[1], "5")==0)
586 return test5(argc, argv);
587 else if (strcasecmp(argv[1], "6")==0)
588 return test6(argc, argv);
589 else if (strcasecmp(argv[1], "7")==0)
590 return test7(argc, argv);
591 else if (strcasecmp(argv[1], "8")==0)
592 return test8(argc, argv);
593 else if (strcasecmp(argv[1], "9")==0)
594 return test9(argc, argv);
595 else if (strcasecmp(argv[1], "10")==0)
596 return test10(argc, argv);
597 else if (strcasecmp(argv[1], "11")==0)
598 return test11(argc, argv);
599 else if (strcasecmp(argv[1], "12")==0)
600 return test12(argc, argv);
601 }
602 else
603 return test1(argc, argv);
604}
605
606
607
#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
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
#define DBG_ERROR_ERR(dbg_logger, dbg_err)
Definition debug.h:113
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:293
#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:348
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:472
#define GWEN_LOGDOMAIN
Definition logger.h:32
@ GWEN_LoggerLevel_Notice
Definition logger.h:67
@ GWEN_LoggerLevel_Debug
Definition logger.h:69
@ GWEN_LoggerLevel_Verbous
Definition logger.h:70
@ GWEN_LoggerLevel_Info
Definition logger.h:68
GWEN_PASSWD_STORE * GWEN_PasswordStore_new(const char *fname)
Definition passwdstore.c:46
struct GWEN_PASSWD_STORE GWEN_PASSWD_STORE
Definition passwdstore.h:37