summaryrefslogtreecommitdiff
path: root/modules/other/gail/tests/testlib.c
blob: 87a17c60cf14cb81255cc5f9e57080b49ac64d21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "testlib.h" 

static gint	_get_position_in_array		(gint		window,
						gchar		*the_test_name);
static gint	_get_position_in_parameters	(gint		window,
						gchar		*label,
						gint		position);
static void	_create_output_window		(OutputWindow	**outwin);
static gboolean	_create_select_tests_window	(AtkObject	*obj,
                                                TLruntest	runtest,
                                                OutputWindow	**outwin);
static void	_toggle_selectedcb		(GtkWidget	*widget,
						gpointer	test);
static void	_testselectioncb		(GtkWidget	*widget,
						gpointer	data);
static void	_destroy			(GtkWidget	*widget,
						gpointer	data);

/* General functions */

/**
 * find_object_by_role:
 * @obj: An #AtkObject
 * @roles: An array of roles to search for
 * @num_roles: The number of entries in @roles
 *
 * Find the #AtkObject which is a decendant of the specified @obj
 * which is of an #AtkRole type specified in the @roles array.
 *
 * Returns: the #AtkObject that meets the specified criteria or NULL
 * if no object is found. 
 **/
AtkObject*
find_object_by_role (AtkObject *obj,
                     AtkRole   *roles,
                     gint      num_roles)
{
  /*
   * Find the first object which is a descendant of the specified object
   * which matches the specified role.
   *
   * This function returns a reference to the AtkObject which should be
   * removed when finished with the object.
   */
  gint i, j;
  gint n_children;
  AtkObject *child;

  if (obj == NULL)
    return NULL;

  for (j=0; j < num_roles; j++)
    {
      if (atk_object_get_role (obj) == roles[j])
        return obj;
    }

  n_children = atk_object_get_n_accessible_children (obj);
  for (i = 0; i < n_children; i++)
    {
      AtkObject* found_obj;

      child = atk_object_ref_accessible_child (obj, i);

      if (child == NULL)
        continue;

      for (j=0; j < num_roles; j++)
        {
          if (atk_object_get_role (child) == roles[j])
            return child;
        }

      found_obj = find_object_by_role (child, roles, num_roles);
      g_object_unref (child);
      if (found_obj)
        return found_obj;
    }
  return NULL;
}

/**
 * find_object_by_name_and_role:
 * @obj: An #AtkObject
 * @name: The GTK widget name
 * @roles: An array of roles to search for
 * @num_roles: The number of entries in @roles
 *
 * Find the #AtkObject which is a decendant of the specified @obj
 * which is of an #AtkRole type specified in the @roles array which
 * also has the GTK widget name specified in @name.
 *
 * Returns: the #AtkObject that meets the specified criteria or NULL
 * if no object is found. 
 **/
AtkObject*
find_object_by_name_and_role(AtkObject   *obj,
                             const gchar *name,
                             AtkRole	 *roles,
                             gint        num_roles)
{
  AtkObject *child;
  GtkWidget* widget;
  gint i, j;
  gint n_children;

  if (obj == NULL)
    return NULL;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
  if (GTK_IS_WIDGET (widget))
    {
      if (strcmp (name, gtk_widget_get_name(GTK_WIDGET (widget))) == 0)
        {
          for (j=0; j < num_roles; j++)
            {
              if (atk_object_get_role (obj) == roles[j])
                return obj;
            }
        }
    }

  n_children = atk_object_get_n_accessible_children (obj);
  for (i = 0; i < n_children; i++)
    {
      AtkObject* found_obj;
 
      child = atk_object_ref_accessible_child (obj, i);

      if (child == NULL)
        continue;

      widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (child));
      if (GTK_IS_WIDGET (widget))
        {
          if (strcmp(name, gtk_widget_get_name(GTK_WIDGET (widget))) == 0)
            {
              for (j=0; j < num_roles; j++)
                {
                  if (atk_object_get_role (child) == roles[j])
                    return child;
                }
            }
        }
      found_obj = find_object_by_name_and_role (child, name, roles, num_roles);
      g_object_unref (child);
      if (found_obj)
        return found_obj;
    }
  return NULL;
}

/**
 * find_object_by_accessible_name_and_role:
 * @obj: An #AtkObject
 * @name: The accessible name
 * @roles: An array of roles to search for
 * @num_roles: The number of entries in @roles
 *
 * Find the #AtkObject which is a decendant of the specified @obj
 * which has the specified @name and matches one of the 
 * specified @roles.
 * 
 * Returns: the #AtkObject that meets the specified criteria or NULL
 * if no object is found. 
 */
AtkObject*
find_object_by_accessible_name_and_role (AtkObject   *obj,
                                         const gchar *name,
                                         AtkRole     *roles,
	                                 gint        num_roles)
{
  AtkObject *child;
  gint i, j;
  gint n_children;
  G_CONST_RETURN gchar *accessible_name;

  if (obj == NULL)
    return NULL;

  accessible_name = atk_object_get_name (obj);
  if (accessible_name && (strcmp(name, accessible_name) == 0))
    {
      for (j=0; j < num_roles; j++)
        {
          if (atk_object_get_role (obj) == roles[j])
            return obj;
        }
    }

  n_children = atk_object_get_n_accessible_children (obj);
  for (i = 0; i < n_children; i++)
    {
      AtkObject* found_obj;

      child = atk_object_ref_accessible_child (obj, i);

      if (child == NULL)
        continue;

      accessible_name = atk_object_get_name (child);
      if (accessible_name && (strcmp(name, accessible_name) == 0))
        {
          for (j=0; j < num_roles; j++)
            {
              if (atk_object_get_role (child) == roles[j])
                return child;
            }
        }
      found_obj = find_object_by_accessible_name_and_role (child, name, 
                                                           roles, num_roles);
      g_object_unref (child);
      if (found_obj)
        return found_obj;
    }
  return NULL;
}

/**
 * find_object_by_name_and_role:
 * @obj: An #AtkObject
 * @type: The type 
 *
 * Find the #AtkObject which is a decendant of the specified @obj
 * which has the specified @type.
 * 
 * Returns: the #AtkObject that meets the specified criteria or NULL
 * if no object is found. 
 */
AtkObject*
find_object_by_type (AtkObject *obj, 
                     gchar     *type)
{
  /*
   * Find the first object which is a descendant of the specified object
   * which matches the specified type.
   *
   * This function returns a reference to the AtkObject which should be
   * removed when finished with the object.
   */
  gint i;
  gint n_children;
  AtkObject *child;
  G_CONST_RETURN gchar * typename = NULL;

  if (obj == NULL)
    return NULL;

  typename = g_type_name (G_OBJECT_TYPE (obj));
  if (strcmp (typename, type) == 0)
     return obj;

  n_children = atk_object_get_n_accessible_children (obj);
  for (i = 0; i < n_children; i++)
    {
      AtkObject* found_obj;

      child = atk_object_ref_accessible_child (obj, i);

      if (child == NULL)
        continue;

      typename = g_type_name (G_OBJECT_TYPE (child));

      if (strcmp (typename, type) == 0)
        return child;

      found_obj = find_object_by_type (child, type);
      g_object_unref (child);
      if (found_obj)
        return found_obj;
    }
  return NULL;
}

/**
 * already_accessed_atk_object
 * @obj: An #AtkObject
 *
 * Keeps a static GPtrArray of objects that have been passed into this
 * function. 
 *
 * Returns: TRUE if @obj has been passed into this function before
 * and FALSE otherwise.
 */
gboolean
already_accessed_atk_object (AtkObject *obj)
{
  static GPtrArray *obj_array = NULL;
  gboolean found = FALSE;
  gint i;

  /*
   * We create a property handler for each object if one was not associated
   * with it already.
   *
   * We add it to our array of objects which have property handlers; if an
   * object is destroyed it remains in the array.
   */
  if (obj_array == NULL)
    obj_array = g_ptr_array_new ();

  for (i = 0; i < obj_array->len; i++)
    {
      if (obj == g_ptr_array_index (obj_array, i))
        {
          found = TRUE;
          break;
        }
    }
  if (!found)
    g_ptr_array_add (obj_array, obj);

  return found;
}

/**
 * display_children
 * @obj: An #AtkObject
 * @depth: Number of spaces to indent output.
 * @child_number: The child number of this object.
 *
 * Displays the hierarchy of widgets starting from @obj.
 **/
void
display_children (AtkObject *obj, 
                  gint      depth, 
                  gint      child_number)
{
  display_children_to_depth(obj, -1, depth, child_number);
}

/**
 * display_children_to_depth
 * @obj: An #AtkObject
 * @to_depth: Display to this depth.
 * @depth: Number of spaces to indent output.
 * @child_number: The child number of this object.
 *
 * Displays the hierarchy of widgets starting from @obj only
 * to the specified depth.
 **/
void
display_children_to_depth (AtkObject *obj,
                           gint      to_depth,
                           gint      depth,
                           gint      child_number)
{
  AtkRole role;
  const gchar *rolename;
  const gchar *typename;
  gint n_children, parent_index, i;

  if (to_depth >= 0 && depth > to_depth)
     return;

  if (obj == NULL)
     return;

  for (i=0; i < depth; i++)
    g_print(" ");

  role = atk_object_get_role (obj);
  rolename = atk_role_get_name (role);

 /*
  * Note that child_number and parent_index should be the same
  * unless there is an error.
  */
  parent_index = atk_object_get_index_in_parent(obj);
  g_print("child <%d == %d> ", child_number, parent_index);

  n_children = atk_object_get_n_accessible_children (obj);
  g_print ("children <%d> ", n_children);

  if (rolename)
    g_print("role <%s>, ", rolename);
  else
    g_print("role <error>");

  if (GTK_IS_ACCESSIBLE(obj))
    {
      GtkWidget *widget;

      widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
      g_print("name <%s>, ", gtk_widget_get_name(GTK_WIDGET (widget)));
    }
  else
    g_print("name <NULL>, ");

  typename = g_type_name (G_OBJECT_TYPE (obj));
  g_print ("typename <%s>\n", typename);

  for (i = 0; i < n_children; i++)
    {
      AtkObject *child;

      child = atk_object_ref_accessible_child (obj, i);
      if (child != NULL)
        {
          display_children_to_depth (child, to_depth, depth + 1, i);
          g_object_unref (G_OBJECT (child));
        }
    }
}

/* Test GUI logic */

/* GUI Information for the Select Tests Window */
typedef struct
{
  GtkWidget     *selecttestsWindow;
  GtkWidget     *hbox;
  GtkWidget     *vbox;
  GtkWidget     *label;
  GtkWidget     *textInsert;
  GtkWidget     *button;
  gchar         *selecttestsTitle;
}MainDialog;

/* Functionality information about each added test */
typedef struct
{
  GtkWidget     *toggleButton;
  GtkWidget     *hbox;
  GtkWidget     *parameterLabel[MAX_PARAMS];
  GtkWidget     *parameterInput[MAX_PARAMS];
  gchar         *testName;
  gint          numParameters;
}TestList;

typedef struct
{
   TLruntest   runtest;
   AtkObject*  obj;
   gint	       win_num;
}TestCB;

static MainDialog      *md[MAX_WINDOWS];
static OutputWindow    *ow;

/* An array containing function information on all of the tests */
static TestList        listoftests[MAX_WINDOWS][MAX_TESTS];

/* A counter for the actual number of added tests */
gint                   counter;

/* A global for keeping track of the window numbers */
static gint 	       window_no = 0;
/* An array containing the names of the tests that are "on" */
static gchar           *onTests[MAX_WINDOWS][MAX_TESTS]; 
static gint            g_visibleDialog = 0;
static gint	       testcount[MAX_WINDOWS];
static TestCB          testcb[MAX_WINDOWS];

/**
 * create_windows:
 * @obj: An #AtkObject
 * @runtest: The callback function to run when the "Run Tests" button
 *   is clicked.
 * @outwin: The output window to use.  If NULL is passed in, then 
 *   create a new one.
 *
 * Creates the test window and the output window (if @outwin is NULL)
 * Runs _create_output_window() and _create_select_tests_window() 
 * and sets g_visibleDialog to 1
 *
 * Returns: The window number of the created window if successful, -1 otherwise.
 **/
gint
create_windows (AtkObject    *obj,
                TLruntest    runtest,
                OutputWindow **outwin)
{
  gboolean valid;  
  gint tmp;

  g_visibleDialog = 1;
  _create_output_window(outwin); 
  valid = _create_select_tests_window(obj, runtest, outwin);
  if (valid)
    {
      tmp = window_no;
      window_no++;
      return tmp;
    }
  else
    return -1;
}

/** 
 * _create_output_window
 * @outwin: If outwin is passed in as NULL, a new output window is created
 *   otherwise, the outwin passed in is shared.
 *
 * Creates the Test Result Output Window .
 **/
static void
_create_output_window (OutputWindow **outwin)
{
  GtkWidget *view;
  GtkWidget *scrolled_window;
  OutputWindow *localow;

  if (*outwin == NULL)
    {
      localow = (OutputWindow *) malloc (sizeof(OutputWindow));
   
      localow->outputBuffer = gtk_text_buffer_new(NULL);
      view = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(localow->outputBuffer));
      gtk_widget_set_size_request (view, 700, 500);
      gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
      gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);	

      localow->outputWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title(GTK_WINDOW(localow->outputWindow), "Test Output");
      scrolled_window = gtk_scrolled_window_new(NULL, NULL);

      gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
                                     GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
      gtk_container_add(GTK_CONTAINER(localow->outputWindow), scrolled_window);
      gtk_container_add(GTK_CONTAINER(scrolled_window), view);
      gtk_text_buffer_get_iter_at_offset(localow->outputBuffer, &localow->outputIter, 0);
      gtk_widget_show(view);
      gtk_widget_show(scrolled_window);
      gtk_widget_show(localow->outputWindow);

      gtk_text_buffer_set_text(GTK_TEXT_BUFFER(localow->outputBuffer),
        "\n\nWelcome to the test GUI:\nTest results are printed here\n\n", 58);
      gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(localow->outputBuffer),
                                          &localow->outputIter, 0);
      *outwin = localow;
      ow = *outwin;
    }
}

/** 
 * _create_select_tests_window:
 * @obj: An #AtkObject
 * @runtest: The callback function that is run when the "Run Tests"
 *   button is clicked.
 * @outwin: The output window to use.
 *
 * Creates the Test Select Window 
 *
 * Returns: TRUE if successful, FALSE otherwise
 **/
static gboolean
_create_select_tests_window (AtkObject    *obj,
                             TLruntest    runtest,
                             OutputWindow **outwin)
{
  AtkText   *textwidget;
  GtkWidget *hbuttonbox;
  GtkWidget *scrolledWindow;

  if (window_no >= 0 && window_no < MAX_WINDOWS)
    {
      md[window_no] = (MainDialog *) malloc (sizeof(MainDialog));
     
      textwidget = ATK_TEXT (obj);
     
      /* Setup Window */
      md[window_no]->selecttestsTitle = "Test Setting";
      md[window_no]->selecttestsWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title (GTK_WINDOW( ow->outputWindow),
                            md[window_no]->selecttestsTitle);
      gtk_window_set_resizable (GTK_WINDOW(md[window_no]->selecttestsWindow),
                                FALSE);
      gtk_window_set_position (GTK_WINDOW(md[window_no]->selecttestsWindow),
                               GTK_WIN_POS_CENTER); 
      g_signal_connect (md[window_no]->selecttestsWindow, 
                        "destroy",
                        G_CALLBACK (_destroy),
                        &md[window_no]->selecttestsWindow);
     
      /* Setup Scrolling */
      scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledWindow),
                                      GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); 
      gtk_widget_set_size_request (scrolledWindow, 500, 600);
      gtk_container_add (GTK_CONTAINER (md[window_no]->selecttestsWindow), 
                         scrolledWindow);
      
      /* Setup Layout */
      md[window_no]->vbox = gtk_vbox_new (TRUE, 0);
      md[window_no]->button = gtk_button_new_with_mnemonic ("_Run Tests");
      hbuttonbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
      gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox),
                                 GTK_BUTTONBOX_SPREAD);
      gtk_box_pack_end (GTK_BOX (hbuttonbox),
                        GTK_WIDGET (md[window_no]->button), TRUE, TRUE, 0);
      gtk_box_pack_end (GTK_BOX (md[window_no]->vbox), hbuttonbox,
                        TRUE, TRUE, 0);
      gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledWindow),
                                             md[window_no]->vbox);

      testcb[window_no].runtest = runtest;
      testcb[window_no].obj = obj;
      testcb[window_no].win_num = window_no; 
      g_signal_connect (md[window_no]->button, 
                        "clicked",
                        G_CALLBACK (_testselectioncb),
                        (gpointer)&testcb[window_no]);
     
      /* Show all */
      gtk_widget_grab_focus (md[window_no]->button);
      gtk_widget_show (md[window_no]->button);
      gtk_widget_show (hbuttonbox); 
      gtk_widget_show (scrolledWindow); 
      gtk_widget_show_all (GTK_WIDGET (md[window_no]->selecttestsWindow));
      return TRUE;
    }
  else
    return FALSE;
}

/** 
 * add_test
 * @window: The window number
 * @name: The test name
 * @num_params: The number of arguments the test uses.
 * @parameter_names: The names of each argument.
 * @default_names: The default values of each argument.
 *
 * Adds a Test with the passed-in details to the Tests Select Window.  
 *
 * Returns: FALSE if the num_params passed in is greater than
 * MAX_PARAMS, otherwise returns TRUE 
 *
 **/
gboolean
add_test (gint   window, 
          gchar  *name,
          gint   num_params,
          gchar* parameter_names[],
          gchar* default_names[])
{
  gint i;

  if (num_params > MAX_PARAMS)
    return FALSE;
  else
    {
      md[window]->hbox = gtk_hbox_new (FALSE, 0);
      gtk_box_set_spacing (GTK_BOX (md[window]->hbox), 10);
      gtk_container_set_border_width (GTK_CONTAINER (md[window]->hbox), 10);
      gtk_container_add (GTK_CONTAINER (md[window]->vbox), md[window]->hbox);
      listoftests[window][testcount[window]].toggleButton =
         gtk_toggle_button_new_with_label (name);
      gtk_box_pack_start (GTK_BOX (md[window]->hbox),
          listoftests[window][testcount[window]].toggleButton, FALSE, FALSE, 0);
      listoftests[window][testcount[window]].testName = name;
      listoftests[window][testcount[window]].numParameters = num_params;
      for (i=0; i<num_params; i++) 
        {
     	  listoftests[window][testcount[window]].parameterLabel[i] =
            gtk_label_new (parameter_names[i]);
          gtk_box_pack_start (GTK_BOX (md[window]->hbox),
          listoftests[window][testcount[window]].parameterLabel[i], FALSE, FALSE, 0);
	  listoftests[window][testcount[window]].parameterInput[i] = gtk_entry_new();
          gtk_entry_set_text (GTK_ENTRY (listoftests[window][testcount[window]].parameterInput[i]),
            default_names[i]);
          gtk_widget_set_size_request (listoftests[window][testcount[window]].parameterInput[i], 50, 22);
	  gtk_box_pack_start (GTK_BOX (md[window]->hbox),
            listoftests[window][testcount[window]].parameterInput[i], FALSE, FALSE, 0);
          gtk_widget_set_sensitive (
            GTK_WIDGET (listoftests[window][testcount[window]].parameterLabel[i]), FALSE);
          gtk_widget_set_sensitive (
            GTK_WIDGET (listoftests[window][testcount[window]].parameterInput[i]), FALSE);
	  gtk_widget_show (listoftests[window][testcount[window]].parameterLabel[i]);
	  gtk_widget_show (listoftests[window][testcount[window]].parameterInput[i]);
        }
      g_signal_connect (listoftests[window][testcount[window]].toggleButton,
                        "toggled",
                        G_CALLBACK (_toggle_selectedcb),
                        (gpointer)&(listoftests[window][testcount[window]]));
      gtk_widget_show (listoftests[window][testcount[window]].toggleButton);
      gtk_widget_show (md[window]->hbox);
      gtk_widget_show (md[window]->vbox);

      testcount[window]++;
      counter++;
      return TRUE;
    }  
}

/** 
 * tests_set:
 * @window: The window number
 * @count: Passes back the number of tests on.
 *
 * Gets an array of strings corresponding to the tests that are "on".
 * A test is assumed on if the toggle button is on and if all its
 * parameters have values.
 *
 * Returns: an array of strings corresponding to the tests that
 * are "on".
 **/
gchar **tests_set(gint window, int *count)
{
  gint        i =0, j = 0, num;
  gboolean    nullparam;
  gchar*      input;

  *count = 0;
  for (i = 0; i < MAX_TESTS; i++)
      onTests[window][i] = NULL;

  for (i = 0; i < testcount[window]; i++)
    {
      nullparam = FALSE;
      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (listoftests[window][i].toggleButton)))
        {
          num = listoftests[window][i].numParameters;
          for (j = 0; j < num; j++)
            {
              input = gtk_editable_get_chars (
                    GTK_EDITABLE (listoftests[window][i].parameterInput[j]), 0, -1);

              if (input != NULL && (! strcmp(input, "")))
                nullparam = TRUE;
            } 
          if (!nullparam)
            {
              onTests[window][*count] = listoftests[window][i].testName;
              *count = *count + 1; 
            }
        }
    } 
  return onTests[window];
}

/**
 * _get_position_in_array:
 * @window: The window number
 * @the_test_name: The name of the test
 *
 * Gets the index of the passed-in @the_test_name.
 *
 * Returns: the position in listoftests[] of @the_test_name
 **/
static gint
_get_position_in_array(gint  window,
                       gchar *the_test_name)
{
  gint        i;
  
  for (i = 0; i < testcount[window]; i++)
    {
      if (strcmp(listoftests[window][i].testName, the_test_name) == 0)
        return i;
    }
  return -1;
}

/**
 * _get_position_in_parameters:
 * @window: The window number
 * @label: The label name
 * @position: The parameter position
 *
 * Gets the index of the passed-in parameter @label.
 *
 * Returns: the position in parameterLabel[] (a member of
 * listoftests[]) of @label 
 **/
static gint
_get_position_in_parameters(gint  window,
                            gchar *label,
                            gint  position)
{
  gint                    i;
  G_CONST_RETURN gchar    *label_string;
  
  for (i = 0; i < MAX_PARAMS; i++)
    {
      label_string = gtk_label_get_text( 
               GTK_LABEL (listoftests[window][position].parameterLabel[i]));

      if (strcmp(label_string, label) == 0)
        return i;
    }
  return -1;
}

/** 
 * set_output_buffer:
 * @output: The string to add to the output buffer
 * 
 * Tidies up the output Window 
 **/
void
set_output_buffer(gchar *output)
{
  gtk_text_buffer_insert (GTK_TEXT_BUFFER (ow->outputBuffer),
                          &ow->outputIter, output, strlen(output));
  gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (ow->outputBuffer),
                                      &ow->outputIter, 0);
}

/**
 * isVisibleDialog:
 *
 * Informs user if a visible test window running.
 *
 * Returns: TRUE if g_visibleDialog is set to 1, otherwise FALSE
 **/
gboolean
isVisibleDialog(void)
{
 if (g_visibleDialog >= 1)
   return TRUE;
 else
   return FALSE;
}

/**
 * get_arg_of_func:
 * @window: The window number
 * @function_name: The name of the function
 * @arg_label: The label of the argument.
 *
 * Gets the user input associated with the @function_name and @arg_label.
 *
 * Returns: the user input associated with the @function_name and @arg_label.
 **/
gchar*
get_arg_of_func (gint  window,
                 gchar *function_name,
                 gchar *arg_label)
{
  G_CONST_RETURN gchar       *argString;
  gchar                      *retString;
  gint                       position, paramPosition;

  position =  _get_position_in_array(window, function_name);

  if (position == -1)
    {
      g_print("No such function\n");
      return NULL;
    }

  paramPosition = _get_position_in_parameters(window, arg_label, position);

  if (paramPosition == -1)
    {
      g_print("No such parameter Label\n");
      return NULL;
    }

  if (position != -1 && paramPosition != -1)
    {
      argString = gtk_editable_get_chars (
        GTK_EDITABLE (listoftests[window][position].parameterInput[paramPosition]),
      0, -1);
      retString = g_strdup(argString);
    }
  else
    retString = NULL;

  return retString;
}

/**
 * string_to_int:
 * @the_string: The string to convert
 *
 * Converts the passed-in string to an integer 
 *
 * Returns: An integer corresponding to @the_string.
 **/
int
string_to_int (const char *the_string)
{
  char *end_ptr;
  double ret_val;
  int int_ret_val; 

  while (1)
    {
      ret_val = strtod( the_string, &end_ptr);
      if (*end_ptr == '\0')
        break;
      else
        printf("\nError: input must be a number\n");
    }
   
  int_ret_val = (int) ret_val;
  return (int_ret_val);
}

/** 
 * _toggle_selectedcb:
 * @widget: The ToggleButton widget
 * @test: user data containing the TestList structure.
 *
 * Toggle Button Callback, activating the text entry fields 
 **/
static void
_toggle_selectedcb (GtkWidget *widget,
                    gpointer  test)
{
  int i;
  TestList *testlist = (TestList *) test;
  gboolean toggled;
  gboolean sensitive;
  toggled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
  if (toggled)
    sensitive = TRUE;
  else
    sensitive = FALSE;

  for (i=0; i < testlist->numParameters; i++)
    {
      gtk_widget_set_sensitive (GTK_WIDGET (testlist->parameterLabel[i]),
                                sensitive);
      gtk_widget_set_sensitive (GTK_WIDGET (testlist->parameterInput[i]),
                                sensitive);
    }
}

/* 
 * _testselectioncb:
 * widget: The Button widget
 * data: The user data containing a TestCB structure
 *
 * Callback for when the "Run Tests" button is pressed 
 **/
static void
_testselectioncb (GtkWidget *widget,
                  gpointer data)
{
  TestCB* local_testcb = (TestCB *)data;
  local_testcb->runtest(local_testcb->obj, local_testcb->win_num);
}

/**
 * _destroy:
 * @widget: The GUI widget
 * @data: User data, not used.
 *
 * Destroy Callback.
 **/
static void
_destroy (GtkWidget *widget,
          gpointer  data)
{
  gtk_main_quit();
}