summaryrefslogtreecommitdiff
path: root/tests/Config_Test.cpp
blob: 0c09705e03de1c7ccf9a106aa795ccf9fa6b567d (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
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
// $Id$

// ============================================================================
//
// = LIBRARY
//    tests
//
// = FILENAME
//    Config_Test.cpp
//
// = DESCRIPTION
//      This is a test that makes sure various classes in
//      <ACE_Configuration> work correctly.
//
// = AUTHOR
//    Michael Searles <msearles@base16.com>,
//    Chris Hafey <chafey@stentor.com>, and
//    Jerry D. Odenwelder Jr. <jerry.o@mindspring.com>
//
// ============================================================================

#include "test_config.h"
#include "Config_Test.h"
#include "ace/Configuration_Import_Export.h"

ACE_RCSID(tests, Config_Test, "$Id$")

static int
test (ACE_Configuration *config,
      ACE_Configuration_Section_Key &testsection)
{
  ACE_TString stvalue;

  // Set some values.
  if (config->set_string_value (testsection,
                                ACE_TEXT ("stvalue"),
                                ACE_TEXT ("stvaluetest")))
    return -3;

  else if (config->remove_value (testsection,
                                 ACE_TEXT ("stvalue")))
    return -4;
  // Make sure it's really gone
  else if (0 == config->get_string_value (testsection,
                                          ACE_TEXT ("stvalue"),
                                          stvalue))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("test:remove_value didn't remove\n")),
                      -4);

  else if (config->set_string_value (testsection,
                                     ACE_TEXT ("stvalue"),
                                     ACE_TEXT ("stvaluetest")))
    return -3;
  else if (config->set_string_value (testsection,
                                     ACE_TEXT ("stvalue"),
                                     ACE_TEXT ("second stvaluetest")))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("test:set_string_value twice failed\n")),
                      -3);

  else if (config->set_integer_value (testsection,
                                      ACE_TEXT ("intvalue"),
                                      77))
    return -4;
  // Reset to the value we test for below
  else if (config->set_integer_value (testsection,
                                      ACE_TEXT ("intvalue"),
                                      42))
    return -4;

  u_char data[80];

  for (int i = 0; i < 80; i++)
    data[i] = i + 128;

  if (config->set_binary_value (testsection,
                                ACE_TEXT ("binvalue"),
                                data,
                                80))
    return -5;

  // Get the values and compare
  if (config->get_string_value (testsection,
                                ACE_TEXT ("stvalue"),
                                stvalue))
    return -6;
  else if (stvalue != ACE_TEXT ("second stvaluetest"))
    return -7;

  u_int intvalue;

  if (config->get_integer_value (testsection,
                                 ACE_TEXT ("intvalue"),
                                 intvalue))
    return -8;
  else if (intvalue != 42)
    return -9;

  u_char *data_out = 0;
  size_t length = 0;

  if (config->get_binary_value (testsection,
                                ACE_TEXT ("binvalue"),
                                (void*&) data_out,
                                length))
    return -10;

  // compare em
  for (int j = 0; j < 80; j++)
    if (data_out[j] != data[j])
      return -11;

  delete [] data_out;

  // Test iteration.
  ACE_TString name;
  ACE_Configuration::VALUETYPE type;
  u_int index = 0;
  int found[3] = { 0, 0, 0 };   // One for each expected value

  while (!config->enumerate_values (testsection,
                                    index,
                                    name,
                                    type))
    {
      if (name == ACE_TEXT ("stvalue"))
        {
          if (type != ACE_Configuration::STRING)
            return -12;
          if (found[0] != 0)
            return -12;
          found[0] = 1;
        }
      else if (name == ACE_TEXT ("intvalue"))
        {
          if (type != ACE_Configuration::INTEGER)
            return -13;
          if (found[1] != 0)
            return -13;
          found[1] = 1;
        }
      else if (name == ACE_TEXT ("binvalue"))
        {
          if (type != ACE_Configuration::BINARY)
            return -14;
          if (found[2] != 0)
            return -14;
          found[2] = 1;
        }
      index++;
    }

  // Make sure we got three values.
  if (index != 3 || !found[0] || !found[1] || !found[2])
    return -15;

  // Add some subsections.
  ACE_Configuration_Section_Key test2;
  ACE_Configuration_Section_Key test3;
  ACE_Configuration_Section_Key test4;

  if (config->open_section (testsection,
                            ACE_TEXT ("test2"),
                            1,
                            test2))
    return -16;
  else if (config->open_section (testsection,
                                 ACE_TEXT ("test3"),
                                 1,
                                 test3))
    return -17;
  else if (config->open_section (testsection,
                                 ACE_TEXT ("test4"),
                                 1,
                                 test4))
    return -18;

  // Test enumerate sections.
  index = 0;
  found[0] = found[1] = found[2] = 0;
  while (!config->enumerate_sections (testsection,
                                      index,
                                      name))
    {
      if (name == ACE_TEXT ("test2"))
        {
          if (found[0] != 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("enumerate_sections, dupl test2\n")),
                              -19);
          found[0] = 1;
        }
      else if (name == ACE_TEXT ("test3"))
        {
          if (found[1] != 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("enumerate_sections, dupl test3\n")),
                              -19);
          found[1] = 1;
        }
      else if (name == ACE_TEXT ("test4"))
        {
          if (found[2] != 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("enumerate_sections, dupl test4\n")),
                              -19);
          found[2] = 1;
        }
      index++;
    }

  if (index != 3 || !found[0] || !found[1] || !found[2])
    return -19;

  // Remove a subsection
  if (config->remove_section (testsection,
                              ACE_TEXT ("test2"),
                              0))
    return -20;

  // Try to remove it again
  if (!config->remove_section (testsection,
                               ACE_TEXT ("test2"),
                               0))
    return -21;

  return 0;
}

static int
test (ACE_Configuration *config)
{
  const ACE_Configuration_Section_Key& root =
    config->root_section ();

  ACE_Configuration_Section_Key testsection;

  if (config->open_section (root,
                            ACE_TEXT ("test"),
                            1,
                            testsection))
    return -2;

  int ret_val = test (config, testsection);
  if (ret_val)
    return ret_val;

  // Try to remove the testsection root, it should fail since it still
  // has subkeys
  if (!config->remove_section (root,
                               ACE_TEXT ("test"),
                               0))
    return -22;

  // Test find section
  ACE_Configuration_Section_Key result;

  if (config->open_section (root,
                            ACE_TEXT ("test"),
                            0,
                            result))
    return -23;

  // Now test the recursive remove.
  if (config->remove_section (root,
                              ACE_TEXT ("test"),
                              1))
    return -24;

  // Make sure its not there
  if (!config->open_section (root,
                             ACE_TEXT ("test"),
                             0,
                             testsection))
    return -25;

  return 0;
}

static int
test_subkey_path (ACE_Configuration* config)
{
  ACE_Configuration_Section_Key root =
    config->root_section ();

  ACE_Configuration_Section_Key testsection;

  if (config->open_section (root,
                            ACE_TEXT ("Software\\ACE\\test"),
                            1,
                            testsection))
    return -26;

  int ret_val = test (config, testsection);
  if (ret_val)
    return ret_val;

  if (config->open_section (root,
                            ACE_TEXT ("Software"),
                            0,
                            testsection))
    return -27;

  if (config->remove_section (testsection,
                              ACE_TEXT ("ACE"),
                              1))
    return -28;

  return 0;
}

static int
run_tests (void)
{
  int status;

  {
    // Test import of a legit INI format from a previously-existing file.
    ACE_Configuration_Heap cf;
    if ((status = cf.open ()) != 0)
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ACE_Configuration_Heap::open returned %d\n"),
                  status));
    ACE_Ini_ImpExp import (cf);
    // This one should work...
    status = import.import_config (ACE_TEXT ("Config_Test_Import_1.ini"));
    if (status != 0) {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
                  ACE_TEXT ("Config_Test_Import_1.ini failed")));
    }
    else {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Config_Test_Import_1.ini imported\n")));

      // Imported clean; verify content.  See ini file for expected content.
      // Verify the expected sections are there, but no others. Verify the
      // expected keys are there, but no others.
      int section1_seen = 0, section2_seen = 0;
      int somekey_seen = 0, someotherkey_seen = 0;
      int index;
      ACE_TString sect_name;
      const ACE_Configuration_Section_Key &root = cf.root_section ();
      for (index = 0;
           (status = cf.enumerate_sections (root, index, sect_name)) == 0;
           ++index) {
        if (index > 1)   // There are only two sections.
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Enumerated %d sections; expected 2\n"),
                      index + 1));
        else {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Enumerated to section %s\n"),
                      sect_name.c_str ()));
          if (sect_name == ACE_TEXT ("SectionOne")) {
            if (section1_seen)
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %s multiple times!\n"),
                          sect_name.c_str ()));
            section1_seen = 1;
            // Check for values in this section.
            ACE_Configuration_Section_Key sect1;
            if (cf.open_section (root, sect_name.c_str (), 0, sect1) != 0)
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to open section: %s\n"),
                          sect_name.c_str ()));
            else {
              int val_index = 0, val_status;
              ACE_TString val_name, value;
              ACE_Configuration::VALUETYPE val_type;
              while ((val_status =
                      cf.enumerate_values
                      (sect1, val_index, val_name, val_type)) == 0) {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("Enumerated %s, type %d\n"),
                            val_name.c_str (),
                            val_type));
                if (val_type != ACE_Configuration::STRING)
                  ACE_ERROR ((LM_ERROR,
                              ACE_TEXT ("Expected %s to be STRING, but %d\n"),
                              val_name.c_str (),
                              val_type));
                if (val_name == ACE_TEXT ("SomeKey")) {
                  if (somekey_seen)
                    ACE_ERROR ((LM_ERROR,
                                ACE_TEXT ("Saw %s more than once\n"),
                                val_name.c_str ()));
                  somekey_seen = 1;
                }
                else
                  ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unexpected key %s\n"),
                              val_name.c_str ()));
                if ((val_status = cf.get_string_value
                                     (sect1, val_name.c_str (), value)) != 0)
                  ACE_ERROR ((LM_ERROR, ACE_TEXT ("Can't get value of %s\n"),
                              val_name.c_str ()));
                else {
                  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s value: %s\n"),
                              val_name.c_str (), value.c_str ()));
                  if (value != ACE_TEXT ("SomeValue")) {
                    ACE_ERROR ((LM_ERROR,
                                ACE_TEXT ("SomeKey: %s; expected SomeValue\n")));
                  }
                }
                ++val_index;
              }
              if (val_status == 1) {
                if (val_index != 1)     // Should have only seen 1
                  ACE_ERROR ((LM_ERROR,
                              ACE_TEXT ("Expected 1 value; saw %d\n"),
                              index));
              }
              else
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("Error enumerating %s; status %d\n"),
                            sect_name.c_str (), val_status));
            }
          }
          else if (sect_name == ACE_TEXT ("SectionTwo")) {
            if (section2_seen)
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Saw %s multiple times!\n"),
                          sect_name.c_str ()));
            section2_seen = 1;
            // Check for values in this section.
            ACE_Configuration_Section_Key sect2;
            if (cf.open_section (root, sect_name.c_str (), 0, sect2) != 0)
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("Failed to open section: %s\n"),
                          sect_name.c_str ()));
            else {
              int val_index = 0, val_status;
              ACE_TString val_name, value;
              ACE_Configuration::VALUETYPE val_type;
              while ((val_status = cf.enumerate_values
                        (sect2, val_index, val_name, val_type)) == 0) {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("Enumerated %s, type %d\n"),
                            val_name.c_str (),
                            val_type));
                if (val_type != ACE_Configuration::STRING)
                  ACE_ERROR ((LM_ERROR,
                              ACE_TEXT ("Expected %s to be STRING, but %d\n"),
                              val_name.c_str (), val_type));
                if (val_name == ACE_TEXT ("SomeOtherKey")) {
                  if (someotherkey_seen)
                    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %s more than once\n"),
                                val_name.c_str ()));
                  someotherkey_seen = 1;
                }
                else
                  ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unexpected key %s\n"),
                              val_name.c_str ()));
                if ((val_status = cf.get_string_value
                                     (sect2, val_name.c_str (), value)) != 0)
                  ACE_ERROR ((LM_ERROR, ACE_TEXT ("Can't get value of %s\n"),
                              val_name.c_str ()));
                else {
                  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s value: %s\n"),
                              val_name.c_str (), value.c_str ()));
                  if (value != ACE_TEXT ("SomeOtherValue")) {
                    ACE_ERROR ((LM_ERROR,
                                ACE_TEXT ("SomeOtherKey: %s; expected SomeOtherValue\n")));
                  }
                }
                ++val_index;
              }
              if (val_status == 1) {
                if (val_index != 1)     // Should have only seen 1
                  ACE_ERROR ((LM_ERROR,
                              ACE_TEXT ("Expected 1 value; saw %d\n"),
                              index));
              }
              else
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("Error enumerating %s; status %d\n"),
                            sect_name.c_str (), val_status));
            }
          }
          else {
            ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw unexpected section: %s\n"),
                        sect_name.c_str ()));
          }
        }
      }
      if (status == 1) {    // Ran out of sections
        if (index != 2)
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %d sections; expected 2\n"),
                      index));
      }
      else
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Error enumerating sections; status %d\n"),
                    status));
    }
  }

#if defined (ACE_WIN32)
  {
    ACE_Configuration_Win32Registry RegConfig (HKEY_LOCAL_MACHINE);
    int result = test_subkey_path (&RegConfig);
    if (result)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Win32Registry test HKEY_LOCAL_MACHINE")
                         ACE_TEXT (" failed (%d)\n"), result),
                        -1);
  }
  // test win32 registry implementation.
  HKEY root =
    ACE_Configuration_Win32Registry::resolve_key (HKEY_LOCAL_MACHINE,
                                                  ACE_TEXT ("Software\\ACE\\test"));
  if (!root)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("resolve_key is broken\n")), -2);

  // test resolving of forward slashes
  HKEY root_fs =
    ACE_Configuration_Win32Registry::resolve_key (HKEY_LOCAL_MACHINE,
                                                  ACE_TEXT ("Software/ACE/test"), 0);
  if (!root_fs)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("resolve_key resolving slashes is broken\n")),
                      -2);

  ACE_Configuration_Win32Registry RegConfig (root);
  {
    int result = test (&RegConfig);
    if (result)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Win32 registry test root failed (%d)\n"),
                         result),
                        -1);
  }

#endif /* ACE_WIN32 */
  // Test Heap version
  ACE_Configuration_Heap heap_config;

  if (heap_config.open ())
    return 0;
  {
    int result = test_subkey_path (&heap_config);
    if (result)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Heap Config subkey test failed (%d)\n"),
                         result),
                        -1);
  }

  {
    int result = test (&heap_config);
    if (result)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Heap Configuration test failed (%d)\n"),
                         result),
                        -1);
  }

  // Test persistent heap version
  ACE_OS::unlink (ACE_TEXT ("test.reg"));
  ACE_Configuration_Heap pers_config;

  if (pers_config.open (ACE_TEXT ("test.reg")))
    return 0;
  {
    int result = test (&pers_config);
    if (result)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Persistent Heap Config test failed (%d)\n"),
                         result),
                        -1);
  }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Test passed\n")));
  return 0;
}

static int
build_config_object (ACE_Configuration& cfg)
{
  ACE_Configuration_Section_Key root = cfg.root_section ();
  ACE_Configuration_Section_Key NetworkSection;
  ACE_Configuration_Section_Key LoggerSection;
  ACE_Configuration_Section_Key BinarySection;

  if (cfg.open_section (root,
                        ACE_TEXT ("network"),
                        1,
                        NetworkSection))
    return -1;

  if (cfg.set_integer_value (NetworkSection,
                             ACE_TEXT ("TimeToLive"),
                             100))
    return -2;
  else if (cfg.set_string_value (NetworkSection,
                                 ACE_TEXT ("Delay"),
                                 ACE_TString (ACE_TEXT ("FALSE"))))
    return -3;
  else if (cfg.set_string_value (NetworkSection,
                                 ACE_TEXT ("DestIPAddress"),
                                 ACE_TString (ACE_TEXT ("localhost"))))
    return -4;
  else if (cfg.set_integer_value (NetworkSection,
                                  ACE_TEXT ("DestPort"),
                                  12670))
    return -5;
  else if (cfg.set_integer_value (NetworkSection,
                                  ACE_TEXT ("ReconnectInterval"),
                                  3))
    return -6;

  if (cfg.open_section (root,
                        ACE_TEXT ("logger"),
                        1,
                        LoggerSection))
    return -7;

  if (cfg.set_string_value (LoggerSection,
                            ACE_TEXT ("Heading"),
                            ACE_TString (ACE_TEXT ("ACE - Adaptive Communication Environment"))))
    return -8;
  else if (cfg.set_integer_value (LoggerSection,
                                  ACE_TEXT ("SeekIndex"),
                                  14))
    return -9;
  else if (cfg.set_integer_value (LoggerSection,
                                  ACE_TEXT ("TraceLevel"),
                                  6))
    return -10;
  else if (cfg.set_string_value (LoggerSection,
                                 ACE_TEXT ("Justification"),
                                 ACE_TString (ACE_TEXT ("left_justified"))))
    return -11;
  else if (cfg.set_string_value (LoggerSection,
                                 ACE_TEXT ("LogFilePath"),
                                 ACE_TString (ACE_TEXT ("log/"))))
    return -12;
  else if (cfg.set_string_value (LoggerSection,
                                 ACE_TEXT ("TransactionFilePath"),
                                 ACE_TString (ACE_TEXT ("data/"))))
    return -13;

  if (cfg.open_section (root,
                        ACE_TEXT ("binary"),
                        1,
                        BinarySection))
    return -14;

  u_char data[80];

  for (int i = 0; i < 80; i++)
    data[i] = i + 128;

  if (cfg.set_binary_value (BinarySection,
                            ACE_TEXT ("data"),
                            data,
                            80))
    return -15;

  return 0;
}

/*
 * Test ACE_Configuration::operator==
 */
int
Config_Test::testEquality ()
{
  // create and open 2 ACE_Configuration objects.
  ACE_Configuration_Heap  heap1;
  ACE_Configuration_Heap  heap2;
  if ((heap1.open ()) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Cannot open heap1\n")),
                        -1);

    }
  else if ((heap2.open ()) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Cannot open heap2\n")),
                        -1);
    }

  // populate them equally
  build_config_object (heap1);
  build_config_object (heap2);

  // test equality
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should equal...\n")));
  if (heap1 == heap2)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do ;-)\n")));
    }
  else
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("And they do not :-(\n")
                         ACE_TEXT ("operator== Failed when objects equal\n")),
                        -1);
    }

  // add a section and value to heap1
  ACE_Configuration_Section_Key root1 = heap1.root_section ();
  ACE_Configuration_Section_Key NewSection;
  if (heap1.open_section (root1,
                          ACE_TEXT ("NewSection"),
                          1,
                          NewSection))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding section to heap1\n")),
                      -1);
  else if (heap1.set_integer_value (NewSection,
                                    ACE_TEXT ("TestIntValue"),
                                    100))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding value to heap1\n")),
                      -2);

  // test equality
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
  if (heap1 == heap2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("They Do :-(\noperator== Failed ")
                       ACE_TEXT ("when lhs contains data not in rhs\n")),
                      -1);
  else
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not ;-)\n")));

  //
  // add same section to heap2
  //
  ACE_Configuration_Section_Key root2 = heap2.root_section ();
  ACE_Configuration_Section_Key NewSection2;
  if (heap2.open_section (root2,
                          ACE_TEXT ("NewSection"),
                          1,
                          NewSection2))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding section to heap2\n")),
                      -1);
  else if (heap2.set_integer_value (NewSection2,
                                    ACE_TEXT ("TestIntValue"),
                                    100))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding value to heap2\n")),
                      -2);
  else if (heap2.set_integer_value (NewSection2,
                                    ACE_TEXT ("TestIntValue2"),
                                    100))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding second value to heap2\n")),
                      -2);

  // test equality
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
  if (heap1 == heap2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("And They Do :-(\noperator== Failed ")
                       ACE_TEXT ("when rhs contains value not in lhs\n")),
                      -1);
  else
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not ;-)\n")));

  // add new value in heap 1
  if (heap1.set_integer_value (NewSection,
                               ACE_TEXT ("TestIntValue2"),
                               100))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding second value to heap1\n")),
                      -2);

  // test equality
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should be equal...\n")));
  if (heap1 == heap2)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they are ;-)\n")));
  else
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("And they are not :-(\n")
                       ACE_TEXT ("operator== Failed\n")),
                      -1);

  // Add a new section to heap2
  ACE_Configuration_Section_Key AnotherNewSection2;
  if (heap2.open_section (root2,
                          ACE_TEXT ("AnotherNewSection"),
                          1,
                          AnotherNewSection2))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding second section to heap2\n")),
                      -1);
  else if (heap2.set_integer_value (AnotherNewSection2,
                                    ACE_TEXT ("TestIntValue"),
                                    100))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding value in second section")
                       ACE_TEXT (" to heap2\n")),
                      -2);

  // test equality
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
  if (heap1 == heap2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("And they do :-(\noperator== Failed ")
                       ACE_TEXT ("when rhs contains data not in lhs\n")),
                      -1);
  else
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not :-)\n")));

  // add section back to heap1
  ACE_Configuration_Section_Key AnotherNewSection1;
  if (heap1.open_section (root1,
                          ACE_TEXT ("AnotherNewSection"),
                          1,
                          AnotherNewSection1))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding second section to heap1\n")),
                      -1);
  else if (heap1.set_integer_value (AnotherNewSection1,
                                    ACE_TEXT ("TestIntValue"),
                                    100))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Error adding second value to second ")
                       ACE_TEXT ("section in heap1\n")),
                      -2);

  // test equality
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should be equal...\n")));
  if (heap1 == heap2)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they are ;-)\n")));
  else
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("And they are not :-(\n")
                       ACE_TEXT ("operator== Failed\n")),
                      -1);

  this->equality_tested_ = 1;
  return 0;
}

/*
 * Compare INI import data in fromFile to origional data exported (in origional)
 *
 * This compare is destructive to the origional object.
 * I realize that normally you would not do such an obscene thing but
 * this funciton has a special purpose and I know my origional is not needed
 * after calling this routine.
 * This is done because configuration objects that are imported using the INI
 * import store all data as strings. My origional has type information and I need to
 * know if the import worked.
*/
static int
iniCompare (ACE_Configuration_Heap& fromFile, ACE_Configuration_Heap& original)
{
  int rc = 1; // start by guessing they are equal

  int         sectionIndex = 0;
  ACE_TString sectionName;

  const ACE_Configuration_Section_Key& fromFileRoot  = fromFile.root_section ();
  const ACE_Configuration_Section_Key& originalRoot = original.root_section ();
  ACE_Configuration_Section_Key originalSection;
  ACE_Configuration_Section_Key fromFileSection;

  // loop through each section in the fromFile object
  while ((rc) &&
         (!fromFile.enumerate_sections (fromFileRoot,
                                        sectionIndex,
                                        sectionName)) )
    {
      // find that section in the original object
      if (original.open_section (originalRoot,
                                 sectionName.c_str (),
                                 0,
                                 originalSection) != 0)
        // If the original object does not contain the section then we
        // are not equal.
        rc = 0;
      else if (fromFile.open_section (fromFileRoot,
                                      sectionName.c_str (),
                                      0,
                                      fromFileSection) != 0)
        // if there is some error opening the section in the fromFile
        rc = 0;
      else
        {
          // Well the sections match
          int         valueIndex = 0;
          ACE_TString valueName;
          ACE_Configuration::VALUETYPE   valueType;
          ACE_Configuration::VALUETYPE   originalType;

          // Enumerate each value in the fromFile section
          while ((rc) &&
                 (!fromFile.enumerate_values (fromFileSection,
                                              valueIndex,
                                              valueName,
                                              valueType)))
            {
              // look for the same value in the original section
              if (original.find_value (originalSection,
                                       valueName.c_str (),
                                       originalType) != 0)
                // We're not equal if the same value cannot be found
                // in the original object.
                rc = 0;
              else
                {
                  ACE_TString fromFileString, originalString;


                  if (fromFile.get_string_value (fromFileSection,
                                                 valueName.c_str (),
                                                 fromFileString) != 0)
                    // we're not equal if we cannot get this string
                    rc = 0;
                  else if (originalType != ACE_Configuration::STRING)  // If the original type is not a string
                    {
                      // convert original data to a string.

                      if (originalType == ACE_Configuration::INTEGER)
                        {
                          u_int intValue;
                          ACE_TCHAR int_value[32];

                          if (original.get_integer_value (originalSection,
                                                           valueName.c_str (),
                                                           intValue) != 0)
                            // we're not equal if we cannot get rhs int
                            rc = 0;

                          ACE_OS::sprintf (int_value, ACE_LIB_TEXT ("%08x"), intValue);
                          originalString = int_value;
                        }
                      else if (originalType == ACE_Configuration::BINARY)
                        {
                          void* binary_data;
                          size_t binary_length;

                          if (original.get_binary_value (originalSection,
                                                         valueName.c_str (),
                                                         binary_data,
                                                         binary_length))
                            // we're not equal if we cannot get this string
                            rc = 0;
                          else
                            {
                              ACE_TCHAR bin_value[3];

                              unsigned char* ptr = (unsigned char*)binary_data;
                              while (binary_length)
                                {
                                  if (ptr != binary_data)
                                    originalString += ACE_LIB_TEXT (",");

                                  ACE_OS::sprintf (bin_value,
                                                   ACE_LIB_TEXT ("%02x"),
                                                   *ptr);
                                  originalString += bin_value;
                                  --binary_length;
                                  ++ptr;
                                }
                              delete [] (char *)binary_data;
                            }// end successful binary read
                        }// end if originalType was binary
                      else
                        // if the type is invalid, then go ahead and fail it.
                        rc = 0;

                    }// end if the original type was not a string.
                  else
                    {
                      if (original.get_string_value (originalSection,
                                                     valueName.c_str (),
                                                     originalString) != 0)
                        {
                          // we're not equal if we cannot get rhs string
                          rc = 0;
                        }

                    }

                  rc &= fromFileString == originalString;

                  if (rc)
                    // before we move on remove this value from the original.
                    original.remove_value (originalSection,
                                           valueName.c_str ());

                }// end else if values match.

              valueIndex++;

            }// end value while loop

          // at this point the original should have no values.  look
          // for values in the original section
          valueIndex = 0;
          while ((rc) &&
                 (!original.enumerate_values (originalSection,
                                              valueIndex,
                                              valueName,
                                              originalType)))
            valueIndex++;

          // having a value indicates a mismatch
          rc = valueIndex == 0;

        }// end else if sections match.

      if (rc)
        // before we move on remove the section from the original.
        original.remove_section (originalRoot,
                                 sectionName.c_str (),
                                 0); // do not remove subsections.

      sectionIndex++;

    }// end section while loop

  // Finally, if the original has any sections, then we're not equal
  sectionIndex = 0;
  while ((rc) &&
         (!original.enumerate_sections (originalRoot,
                                        sectionIndex,
                                        sectionName)))
    sectionIndex++;

  rc = sectionIndex == 0;

  return rc;
}

// Used to test INI Import Export class

int
Config_Test::testIniFormat ()
{
  int rc = 0;
  if (!this->equality_tested_)
    {
      rc = this->testEquality ();
      if (rc != 0)
        {
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Equality Test Failed\n")));
          return rc;
        }
    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing INI Format Import/Export\n")));
  ACE_Configuration_Heap  fromFile;

  //  1. Creates an ACE_Configuration_Heap object
  ACE_Configuration_Heap original;

  rc = original.open ();
  if (rc == 0)
    {
      rc = build_config_object (original);
      //  2. Calls build_config_object to populate
      if (rc != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Error populating original config ")
                           ACE_TEXT ("object (%d)\n"),
                           rc),
                          -1);

      //  3. Export
      ACE_Ini_ImpExp importExport (original);

      rc = importExport.export_config (ACE_TEXT ("testConfig.ini"));
      if (rc != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Error Exporting (%d)\n"),
                           rc),
                          -1);
    }
  else
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Could not open original object (%d)\n"),
                       rc),
                      -1);

  // At this point we've successfully created, populated and written
  // the configuration object
  //  5. Creates a new ACE_Configuration_Heap object
  rc = fromFile.open ();
  if (rc == 0)
    {
      //  6. Imports
      ACE_Ini_ImpExp importExport (fromFile);

      rc = importExport.import_config (ACE_TEXT ("testConfig.ini"));
      if (rc != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Error Exporting (%d)\n"),
                           rc),
                          -1);

      //  7. Compares to original.
      // This is a special compare since files imported using the
      // INI file import do not contain type information
      //
      // NOTE: After this call the original object will be invalid!!!
      //
      if (!iniCompare (fromFile, original))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Object read from file does not ")
                           ACE_TEXT ("equal original (%d)\n"),
                           rc),
                          -1);
    }// end if heap could not be opened.
  else
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Could not open fromFile object (%d)\n"),
                       rc),
                      -1);

  //  8. Calls old "read_config" methods on the new object

  int       nTimeToLive;
  int       bDelay;
  int       nDestPort;
  int       nReconnectInterval;
  int       nTraceLevel;

  ACE_TCHAR pszDestIPAddress[TEST_MAX_STRING];
  ACE_TCHAR pszLogFilePath[TEST_MAX_STRING];
  ACE_TCHAR pszTransactionFilePath[TEST_MAX_STRING];
  ACE_TCHAR pszHeading[TEST_MAX_STRING];
  ACE_TCHAR pszJustification[TEST_MAX_STRING];

  ACE_Configuration_Section_Key root = fromFile.root_section ();

  // Process [network] section
  ACE_Configuration_Section_Key NetworkSection;
  if (fromFile.open_section (root,
                             ACE_TEXT ("network"),
                             1,
                             NetworkSection) == 0)
    {
      this->get_section_integer (fromFile,
                                 NetworkSection,
                                 ACE_TEXT ("TimeToLive"),
                                 &nTimeToLive,
                                 1,
                                 20);

      this->get_section_boolean (fromFile,
                                 NetworkSection,
                                 ACE_TEXT ("Delay"),
                                 &bDelay);

      this->get_section_string (fromFile,
                                NetworkSection,
                                ACE_TEXT ("DestIPAddress"),
                                pszDestIPAddress,
                                TEST_MAX_STRING);

      this->get_section_integer (fromFile,
                                 NetworkSection,
                                 ACE_TEXT ("DestPort"),
                                 &nDestPort,
                                 0,
                                 65535);

      this->get_section_integer (fromFile,
                                 NetworkSection,
                                 ACE_TEXT ("ReconnectInterval"),
                                 &nReconnectInterval,
                                 0,
                                 65535);
    }// end of "network" section

  // Process [logger] section
  ACE_Configuration_Section_Key LoggerSection;
  if (fromFile.open_section (root,
                             ACE_TEXT ("logger"),
                             1,
                             LoggerSection) == 0)
    {
      this->get_section_string (fromFile,
                                LoggerSection,
                                ACE_TEXT ("Heading"),
                                pszHeading,
                                TEST_MAX_STRING);
      this->get_section_integer (fromFile,
                                 LoggerSection,
                                 ACE_TEXT ("TraceLevel"),
                                 &nTraceLevel,
                                 1,
                                 20);
      this->get_section_string (fromFile,
                                LoggerSection,
                                ACE_TEXT ("Justification"),
                                pszJustification,
                                TEST_MAX_STRING);
      this->get_section_string (fromFile,
                                LoggerSection,
                                ACE_TEXT ("LogFilePath"),
                                pszLogFilePath,
                                TEST_MAX_STRING);
      this->get_section_string (fromFile,
                                LoggerSection,
                                ACE_TEXT ("TransactionFilePath"),
                                pszTransactionFilePath,
                                TEST_MAX_STRING);
    }// end of "logger" section

  if (!rc)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("INI Format Import/Export Works ;-)\n")));
  return rc;
}

// Used to test registry Import Export class

int
Config_Test::testRegFormat ()
{
  int rc = 0;
  if (!this->equality_tested_)
    {
      rc = this->testEquality ();
      if (rc != 0)
        {
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Equality Test Failed\n")));
          return rc;
        }

    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing Registry Format Import/Export\n")));
  ACE_Configuration_Heap  fromFile;

  //  1. Creates an ACE_Configuration_Heap object
  ACE_Configuration_Heap original;

  rc = original.open ();
  if (rc == 0)
    {
      //  2. Calls build_config_object to populate
      rc = build_config_object (original);
      if (rc != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Error populating original config ")
                           ACE_TEXT ("object (%d)\n"),
                           rc),
                          -1);
      //  3. Export
      ACE_Registry_ImpExp importExport (original);

      rc = importExport.export_config (ACE_TEXT ("testConfig.ini"));
      if (rc != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Error Exporting (%d)\n"),
                           rc),
                          -1);
    }
  else
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Could not open original object (%d)\n"),
                       rc),
                      -1);

  // At this point we've successfully created, populated and written
  // the configuration object
  //  5. Creates a new ACE_Configuration_Heap object
  rc = fromFile.open ();
  if (rc == 0)
    {
      //  6. Imports
      ACE_Registry_ImpExp importExport (fromFile);

      rc = importExport.import_config (ACE_TEXT ("testConfig.ini"));
      if (rc != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT("Error Exporting (%d)\n"),
                           rc),
                          -1);

      //  7. Compares to original.
      if (fromFile != original)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Object read from file does not ")
                           ACE_TEXT ("equal original (%d)\n"),
                           rc),
                          -1);
    }// end if heap could not be opened.
  else
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Could not open fromFile object (%d)\n"),
                       rc),
                      -1);

  if (!rc)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Registry Format Import/Export Works ;-)\n")));
  return rc;
}


// Reads a string value from a configuration object.

void
Config_Test::get_section_string (ACE_Configuration&             config,
                                 ACE_Configuration_Section_Key& SectionKey,
                                 const ACE_TCHAR*               pszName,
                                 ACE_TCHAR*                     pszVariable,
                                 int                            nMaxLength)
{
  ACE_TString StringValue;

  if (config.get_string_value (SectionKey,
                               pszName,
                               StringValue) == 0)
    {
      ACE_OS::strncpy (pszVariable,
                       StringValue.c_str (),
                       nMaxLength);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s = %s\n"),
                  pszName,
                  pszVariable));
    }
}

// Reads an integer value from a configuration object (when it's
// stored as a string)
void
Config_Test::get_section_integer (ACE_Configuration&             config,
                                  ACE_Configuration_Section_Key& SectionKey,
                                  const ACE_TCHAR*               pszName,
                                  int*                           nVariable,
                                  int                            nMinValue,
                                  int                            nMaxValue)
{
  ACE_TString StringValue;
  ACE_TCHAR pszString[30];
  ACE_OS::strcpy (pszString, ACE_TEXT ("0"));
  int IntegerValue = 0;

  if (config.get_string_value (SectionKey,
                               pszName,
                               StringValue) == 0)
    {
      ACE_OS::strncpy (pszString,
                       StringValue.c_str (),
                       30);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s = %s\n"),
                  pszName,
                  pszString));
    }

  // convert to integer
  IntegerValue = ACE_OS::atoi (pszString);
  IntegerValue = (IntegerValue < nMinValue) ? nMinValue : IntegerValue;
  IntegerValue = (IntegerValue > nMaxValue) ? nMaxValue : IntegerValue;
  *nVariable = IntegerValue;
}

// Reads a boolean value from a configuration object (when it's stored as a string).

void
Config_Test::get_section_boolean (ACE_Configuration&             config,
                                  ACE_Configuration_Section_Key& SectionKey,
                                  const ACE_TCHAR*               pszName,
                                  int*                           pVariable)
{
  ACE_TString StringValue;
  ACE_TCHAR pszString[10];
  ACE_OS::strcpy (pszString, ACE_TEXT ("0"));

  if (config.get_string_value (SectionKey,
                               pszName,
                               StringValue) == 0)
    {
      ACE_OS::strncpy (pszString,
                       StringValue.c_str (),
                       10);
      for (ACE_TCHAR* pSrc = pszString;
           *pSrc != ACE_TEXT ('\0');
           pSrc++)
        // Convert to uppercase
        if (islower (*pSrc))
          *pSrc = tolower (*pSrc);

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s = %s\n"),
                  pszName,
                  pszString));

      if (ACE_OS::strcmp (pszString,
                          ACE_TEXT ("TRUE")) == 0)
        *pVariable = 1;
      else if (ACE_OS::strcmp (pszString,
                               ACE_TEXT ("FALSE")) == 0)
        *pVariable = 0;
    }
}

int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Config_Test"));

  Config_Test manager;

  if (manager.testEquality () != 0)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the equality Test\n")));

  if (manager.testRegFormat () != 0)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the REG Format Test\n")));

  if (manager.testIniFormat () != 0)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the INI Format Test\n")));

  if (run_tests () != 0)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed in run_tests\n")));

  ACE_END_TEST;
  return 0;
}