gwenhywfar  4.8.0beta
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 
20 #include "../testdialogs/dlg_test.h"
21 #include "../testdialogs/dlg_test2.h"
22 
23 #include <gwenhywfar/gwenhywfar.h>
24 #include <gwenhywfar/debug.h>
25 #include <gwenhywfar/passwdstore.h>
26 
27 #include <unistd.h>
28 
29 
30 
31 int 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 
82 int 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 
145 int test3(int argc, char **argv) {
146  FXApp a("libtest","Martin Preuss");
147  FOX16_HtmlLabel *label;
148  FOX16_Gui *gui;
149  FXDialogBox *dbox;
150  FXVerticalFrame *vf;
151  const char testString[]=
152 #if 1
153  "<h1>Title</h1>"
154  "<h2>Subtitle</h2>"
155  "This is <b>a</b> test. "
156  "And this, is the second line: followed by something else."
157  "<right>This should be right aligned</right>"
158  "<table>"
159  " <tr>"
160  " <th>header1</th>"
161  " <th>header2</th>"
162  " </tr>"
163  " <tr>"
164  " <td>data1</td>"
165  " <td>this is longer data (data2)</td>"
166  " </tr>"
167  "</table>"
168  "And this is after the table.<br>"
169  "and this <font color=\"red\">one</font> is red.";
170 #else
171  "This is before right"
172  "<right>Right</right>"
173  "and this after right.";
174 #endif
175  a.init(argc,argv);
176  a.create();
177 
178  gui=new FOX16_Gui(&a);
180 
181  dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
182  vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
183  0, 0, 0, 0, 1, 1, 1, 1);
184  label=new FOX16_HtmlLabel(vf, FXString(testString), LAYOUT_FILL_X|LAYOUT_FILL_Y);
185  new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
186  new FXLabel(vf, "Normal Testlabel");
187 
188  dbox->create();
189  dbox->resize(300, 200);
190  dbox->show();
191  a.runModalFor(dbox);
192 
193  return 0;
194 }
195 
196 
197 
198 int test4(int argc, char **argv) {
199  FXApp application("libtest","Martin Preuss");
200  FOX16_Gui *gui;
201  int rv;
202  uint32_t id1;
203  uint32_t id2;
204  uint64_t i1;
205  uint64_t i2;
206 
207  application.init(argc,argv);
208 
209  application.create();
210 
211  gui=new FOX16_Gui(&application);
213 
217  "Progress-Title",
218  "<html>"
219  "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
220  "</html>",
221  10,
222  0);
223  for (i1=1; i1<=10; i1++) {
224  char numbuf[128];
225 
226  snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
231  "2nd progress",
232  "Starting 2nd progress...",
233  10,
234  id1);
235  for (i2=1; i2<=10; i2++) {
236  sleep(1);
237  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
238  rv=GWEN_Gui_ProgressAdvance(id2, i2);
239  if (rv==GWEN_ERROR_USER_ABORTED) {
240  fprintf(stderr, "Aborted by user\n");
241  break;
242  }
243  }
245 
246  rv=GWEN_Gui_ProgressAdvance(id1, i1);
247  if (rv==GWEN_ERROR_USER_ABORTED) {
248  fprintf(stderr, "Aborted by user\n");
249  break;
250  }
251  }
252 
254 
255  return 0;
256 }
257 
258 
259 
260 int test5(int argc, char **argv) {
261  FXApp a("libtest","Martin Preuss");
262  FOX16_HtmlText *label;
263  FOX16_Gui *gui;
264  FXDialogBox *dbox;
265  FXVerticalFrame *vf;
266  const char testString[]=
267 #if 1
268  "<h1>Test5</h1>"
269  "<h2>Subtitle</h2>"
270  "This is <b>a</b> test. "
271  "And this, is the second line: followed by something else."
272  "<right>This should be right aligned</right>"
273  "<table>"
274  " <tr>"
275  " <th>header1</th>"
276  " <th>header2</th>"
277  " </tr>"
278  " <tr>"
279  " <td>data1</td>"
280  " <td>this is longer data (data2)</td>"
281  " </tr>"
282  "</table>"
283  "And this is after the table.<br>"
284  "and this <font color=\"red\">one</font> is red.";
285 #else
286  "This is before right"
287  "<right>Right</right>"
288  "and this after right.";
289 #endif
290  a.init(argc,argv);
291  a.create();
292 
293  gui=new FOX16_Gui(&a);
295 
296  dbox=new FXDialogBox(&a, "Test", DECOR_ALL);
297  vf=new FXVerticalFrame(dbox, LAYOUT_FILL_X | LAYOUT_FILL_Y,
298  0, 0, 0, 0, 1, 1, 1, 1);
299  label=new FOX16_HtmlText(vf, FXString(testString),
300  LAYOUT_FILL_X|LAYOUT_FILL_Y |
301  HSCROLLING_OFF | VSCROLLER_ALWAYS);
302  new FXSpring(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
303  new FXLabel(vf, "Normal Testlabel");
304 
305  dbox->create();
306  dbox->resize(300, 200);
307  dbox->show();
308  a.runModalFor(dbox);
309 
310  return 0;
311 }
312 
313 
314 
315 int test6(int argc, char **argv) {
316  FXApp application("libtest","Martin Preuss");
317  FOX16_Gui *gui;
318  int rv;
319  uint32_t id1;
320  uint32_t id2;
321  uint64_t i1;
322  uint64_t i2;
323 
324  application.init(argc,argv);
325 
326  application.create();
327 
328  gui=new FOX16_Gui(&application);
330 
334  "Progress-Title",
335  "<html>"
336  "<p><b>Test</b> f\xc3\xbcr Umlaute.</p>"
337  "</html>",
338  10,
339  0);
340  for (i1=1; i1<=20; i1++) {
341  char numbuf[128];
342 
343  snprintf(numbuf, sizeof(numbuf)-1, "Step %d", (int)i1);
348  "2nd progress",
349  "Starting 2nd progress...",
350  5,
351  id1);
352  for (i2=1; i2<=5; i2++) {
353  sleep(1);
354  fprintf(stderr, "Advancing %d/%d\n", (int)i1, (int)i2);
355  GWEN_Gui_ProgressLog(id2, GWEN_LoggerLevel_Notice, "Advancing...");
356  rv=GWEN_Gui_ProgressAdvance(id2, i2);
357  if (rv==GWEN_ERROR_USER_ABORTED) {
358  fprintf(stderr, "Aborted by user\n");
359  break;
360  }
361  }
363 
364  rv=GWEN_Gui_ProgressAdvance(id1, i1);
365  if (rv==GWEN_ERROR_USER_ABORTED) {
366  fprintf(stderr, "Aborted by user\n");
367  break;
368  }
369  }
370 
372 
373  return 0;
374 }
375 
376 
377 
378 int test7(int argc, char **argv) {
379  FXApp application("libtest","Martin Preuss");
380  FOX16_Gui *gui;
381  char buffer[65];
382 
383  application.init(argc,argv);
384 
385  application.create();
386 
387  gui=new FOX16_Gui(&application);
389 
391  "This is the Title",
392  "<html>This is the text.</html>This is ASCII",
393  buffer,
394  1,
395  sizeof(buffer)-1,
396  0);
397 
398 
399  return 0;
400 }
401 
402 
403 
404 int test8(int argc, char **argv) {
405  FXApp application("libtest","Martin Preuss");
406  FOX16_Gui *gui;
407  int rv;
408  GWEN_DIALOG *dlg;
409 
410  application.init(argc,argv);
411 
412  application.create();
413 
414  gui=new FOX16_Gui(&application);
416 
417 
420 
421  dlg=Dlg_Test1_new();
422  if (dlg==NULL) {
423  fprintf(stderr, "Could not create dialog.\n");
424  return 2;
425  }
426 
427  rv=GWEN_Gui_ExecDialog(dlg, 0);
428  fprintf(stderr, "Result: %d\n", rv);
429 
430  return 0;
431 }
432 
433 
434 
435 int test9(int argc, char **argv) {
436  FXApp application("libtest","Martin Preuss");
437  FOX16_Gui *gui;
438  int rv;
439  GWEN_DIALOG *dlg;
440 
441  application.init(argc,argv);
442 
443  application.create();
444 
445  gui=new FOX16_Gui(&application);
447 
448 
451 
452  dlg=Dlg_Test2_new();
453  if (dlg==NULL) {
454  fprintf(stderr, "Could not create dialog.\n");
455  return 2;
456  }
457 
458  rv=GWEN_Gui_ExecDialog(dlg, 0);
459  fprintf(stderr, "Result: %d\n", rv);
460 
461  return 0;
462 }
463 
464 
465 
466 int test10(int argc, char **argv) {
467  FXApp application("libtest","Martin Preuss");
468  FOX16_Gui *gui;
469  int rv;
470  GWEN_PASSWD_STORE *sto;
471  GWEN_DB_NODE *dbPasswords;
472  const char *token;
473  const char *epw;
474  char pw[256];
475 
476  if (argc<4) {
477  DBG_ERROR(0, "Expected token and secret");
478  return 1;
479  }
480  token=argv[2];
481  epw=argv[3];
482 
483  application.init(argc,argv);
484 
485  application.create();
486 
487  gui=new FOX16_Gui(&application);
489 
490  sto=GWEN_PasswordStore_new("/tmp/pwstore.pw");
491  dbPasswords=GWEN_DB_Group_new("TempPasswords");
492 
493  gui->setPasswordStore(sto);
494  gui->setPasswordDb(dbPasswords, 0);
495 
496 
499 
500  rv=GWEN_Gui_GetPassword(0, token, "Get Password", "Please enter password 1", pw, 4, sizeof(pw)-1, 0);
501  if (rv<0) {
502  DBG_ERROR(0, "Error getting password: %d", rv);
503  return 2;
504  }
505  if (strcmp(epw, pw)!=0) {
506  DBG_ERROR(0, "Bad password for token [%s], expected [%s], got [%s].", token, epw, pw);
507  return 2;
508  }
509 
510 #if 0
511  dlg=Dlg_Test2_new();
512  if (dlg==NULL) {
513  fprintf(stderr, "Could not create dialog.\n");
514  return 2;
515  }
516 
517  rv=GWEN_Gui_ExecDialog(dlg, 0);
518  fprintf(stderr, "Result: %d\n", rv);
519 #endif
520 
521  return 0;
522 }
523 
524 
525 
526 int test11(int argc, char **argv) {
527  FXApp application("libtest","Martin Preuss");
528  FOX16_Gui *gui;
529  char buffer[65];
530 
531  application.init(argc,argv);
532 
533  application.create();
534 
535  gui=new FOX16_Gui(&application);
537 
539  "This is the Title",
540  "<html>This is quite a long HTML text. This is the second sentence, which is a bit longer "
541  "than the first one.<br>In any case this sentence should begin on its own line</html>"
542 
543  "This is quite a long HTML text. This is the second sentence, which is a bit longer "
544  "than the first one.\nIn any case this sentence should begin on its own line.",
545  buffer,
546  1,
547  sizeof(buffer)-1,
548  0);
549 
550 
551  return 0;
552 }
553 
554 
555 
556 int test12(int argc, char **argv) {
557  FXApp application("libtest","Martin Preuss");
558  FOX16_Gui *gui;
559  char buffer[65];
560 
561  application.init(argc,argv);
562 
563  application.create();
564 
565  gui=new FOX16_Gui(&application);
567 
569  "This is the Title",
570  "<html><b>This</b> is quite a long HTML text. This is the second sentence, which is a bit longer "
571  "than the first one.<br>In any case this sentence should begin on its own line.</html>",
572  buffer,
573  1,
574  sizeof(buffer)-1,
575  0);
576 
577 
578  return 0;
579 }
580 
581 
582 
583 
584 int main(int argc, char **argv) {
585  GWEN_Init();
588 
589  if (argc>1) {
590  if (strcasecmp(argv[1], "1")==0)
591  return test1(argc, argv);
592  else if (strcasecmp(argv[1], "2")==0)
593  return test2(argc, argv);
594  else if (strcasecmp(argv[1], "3")==0)
595  return test3(argc, argv);
596  else if (strcasecmp(argv[1], "4")==0)
597  return test4(argc, argv);
598  else if (strcasecmp(argv[1], "5")==0)
599  return test5(argc, argv);
600  else if (strcasecmp(argv[1], "6")==0)
601  return test6(argc, argv);
602  else if (strcasecmp(argv[1], "7")==0)
603  return test7(argc, argv);
604  else if (strcasecmp(argv[1], "8")==0)
605  return test8(argc, argv);
606  else if (strcasecmp(argv[1], "9")==0)
607  return test9(argc, argv);
608  else if (strcasecmp(argv[1], "10")==0)
609  return test10(argc, argv);
610  else if (strcasecmp(argv[1], "11")==0)
611  return test11(argc, argv);
612  else if (strcasecmp(argv[1], "12")==0)
613  return test12(argc, argv);
614  }
615  else
616  return test7(argc, argv);
617 }
618 
619 
620