Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / Config_Test.cpp
blob56d8b26b64cd5899353ed4aa5b1abadd92de7cff
2 //=============================================================================
3 /**
4 * @file Config_Test.cpp
6 * This is a test that makes sure various classes in
7 * <ACE_Configuration> work correctly.
9 * @author Michael Searles <msearles@base16.com>
10 * @author Chris Hafey <chafey@stentor.com>
11 * @author and Jerry D. Odenwelder Jr. <jerry.o@mindspring.com>
13 //=============================================================================
16 #include "test_config.h"
17 #include "Config_Test.h"
18 #include "ace/Configuration_Import_Export.h"
19 #include "ace/OS_NS_ctype.h"
20 #include "ace/OS_NS_errno.h"
21 #include "ace/OS_NS_stdio.h"
22 #include "ace/OS_NS_string.h"
23 #include "ace/OS_NS_unistd.h"
27 static int
28 test (ACE_Configuration *config,
29 ACE_Configuration_Section_Key &testsection)
31 ACE_TString stvalue;
33 // Set some values.
34 if (config->set_string_value (testsection,
35 ACE_TEXT ("stvalue"),
36 ACE_TEXT ("stvaluetest")))
37 return -3;
39 else if (config->remove_value (testsection,
40 ACE_TEXT ("stvalue")))
41 return -4;
42 // Make sure it's really gone
43 else if (0 == config->get_string_value (testsection,
44 ACE_TEXT ("stvalue"),
45 stvalue))
46 ACE_ERROR_RETURN ((LM_ERROR,
47 ACE_TEXT ("test:remove_value didn't remove\n")),
48 -4);
50 else if (config->set_string_value (testsection,
51 ACE_TEXT ("stvalue"),
52 ACE_TEXT ("stvaluetest")))
53 return -3;
54 else if (config->set_string_value (testsection,
55 ACE_TEXT ("stvalue"),
56 ACE_TEXT ("second stvaluetest")))
57 ACE_ERROR_RETURN ((LM_ERROR,
58 ACE_TEXT ("test:set_string_value twice failed\n")),
59 -3);
61 else if (config->set_integer_value (testsection,
62 ACE_TEXT ("intvalue"),
63 77))
64 return -4;
65 // Reset to the value we test for below
66 else if (config->set_integer_value (testsection,
67 ACE_TEXT ("intvalue"),
68 42))
69 return -4;
71 static size_t const data_len = 80;
72 u_char data[data_len];
74 for (size_t i = 0; i < data_len ; ++i)
75 data[i] = static_cast<u_char> (i + 128);
77 if (config->set_binary_value (testsection,
78 ACE_TEXT ("binvalue"),
79 data,
80 data_len))
81 return -5;
83 // Get the values and compare
84 if (config->get_string_value (testsection,
85 ACE_TEXT ("stvalue"),
86 stvalue))
87 return -6;
88 else if (stvalue != ACE_TEXT ("second stvaluetest"))
89 return -7;
91 u_int intvalue;
93 if (config->get_integer_value (testsection,
94 ACE_TEXT ("intvalue"),
95 intvalue))
96 return -8;
97 else if (intvalue != 42)
98 return -9;
100 u_char *data_out (0);
103 void *data_tmp = 0; // Workaround for GCC strict aliasing warning.
104 size_t length = 0;
106 if (config->get_binary_value (testsection,
107 ACE_TEXT ("binvalue"),
108 data_tmp,
109 length))
110 return -10;
112 data_out = reinterpret_cast <u_char *> (data_tmp);
115 u_char * the_data = static_cast<u_char *> (data_out);
117 // compare em
118 for (size_t j = 0; j < data_len; ++j)
119 if (the_data[j] != data[j])
120 return -11;
122 delete [] the_data;
124 // Test iteration.
125 ACE_TString name;
126 ACE_Configuration::VALUETYPE type;
127 u_int index = 0;
128 int found[3] = { 0, 0, 0 }; // One for each expected value
130 while (!config->enumerate_values (testsection,
131 index,
132 name,
133 type))
135 if (name == ACE_TEXT ("stvalue"))
137 if (type != ACE_Configuration::STRING)
138 return -12;
139 if (found[0] != 0)
140 return -12;
141 found[0] = 1;
143 else if (name == ACE_TEXT ("intvalue"))
145 if (type != ACE_Configuration::INTEGER)
146 return -13;
147 if (found[1] != 0)
148 return -13;
149 found[1] = 1;
151 else if (name == ACE_TEXT ("binvalue"))
153 if (type != ACE_Configuration::BINARY)
154 return -14;
155 if (found[2] != 0)
156 return -14;
157 found[2] = 1;
159 index++;
162 // Make sure we got three values.
163 if (index != 3 || !found[0] || !found[1] || !found[2])
164 return -15;
167 // Add some subsections. This part is a separate scope to be sure
168 // the test2, test3, test4 keys are closed before further
169 // manipulating/deleting the sections further down in the test.
170 ACE_Configuration_Section_Key test2;
171 ACE_Configuration_Section_Key test3;
172 ACE_Configuration_Section_Key test4;
174 if (config->open_section (testsection,
175 ACE_TEXT ("test2"),
177 test2))
178 return -16;
179 else if (config->open_section (testsection,
180 ACE_TEXT ("test3"),
182 test3))
183 return -17;
184 else if (config->open_section (testsection,
185 ACE_TEXT ("test4"),
187 test4))
188 return -18;
191 // Test enumerate sections.
192 index = 0;
193 found[0] = found[1] = found[2] = 0;
194 while (!config->enumerate_sections (testsection,
195 index,
196 name))
198 if (name == ACE_TEXT ("test2"))
200 if (found[0] != 0)
201 ACE_ERROR_RETURN ((LM_ERROR,
202 ACE_TEXT ("enumerate_sections, dupl test2\n")),
203 -19);
204 found[0] = 1;
206 else if (name == ACE_TEXT ("test3"))
208 if (found[1] != 0)
209 ACE_ERROR_RETURN ((LM_ERROR,
210 ACE_TEXT ("enumerate_sections, dupl test3\n")),
211 -19);
212 found[1] = 1;
214 else if (name == ACE_TEXT ("test4"))
216 if (found[2] != 0)
217 ACE_ERROR_RETURN ((LM_ERROR,
218 ACE_TEXT ("enumerate_sections, dupl test4\n")),
219 -19);
220 found[2] = 1;
222 index++;
225 if (index != 3 || !found[0] || !found[1] || !found[2])
226 return -19;
228 // Remove a subsection
229 if (config->remove_section (testsection,
230 ACE_TEXT ("test2"),
232 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p (%d)\n"),
233 ACE_TEXT ("remove_section test2"),
234 ACE_OS::last_error ()),
235 -20);
237 // Try to remove it again
238 if (!config->remove_section (testsection,
239 ACE_TEXT ("test2"),
241 return -21;
243 return 0;
246 static int
247 test (ACE_Configuration *config)
249 const ACE_Configuration_Section_Key& root =
250 config->root_section ();
253 // Scope this so the testsection key is closed before trying to
254 // remove the "test" section.
255 ACE_Configuration_Section_Key testsection;
257 if (config->open_section (root,
258 ACE_TEXT ("test"),
260 testsection))
261 return -2;
263 int ret_val = test (config, testsection);
264 if (ret_val)
265 return ret_val;
268 // Try to remove the testsection root, it should fail since it still
269 // has subkeys
270 if (!config->remove_section (root,
271 ACE_TEXT ("test"),
273 return -22;
276 // Test find section, and be sure the key is closed before testing the
277 // remove, below.
278 ACE_Configuration_Section_Key result;
280 if (config->open_section (root,
281 ACE_TEXT ("test"),
283 result))
284 return -23;
287 // Now test the recursive remove.
288 if (config->remove_section (root,
289 ACE_TEXT ("test"),
291 return -24;
293 // Make sure its not there
294 ACE_Configuration_Section_Key testsectiongone;
295 if (!config->open_section (root,
296 ACE_TEXT ("test"),
298 testsectiongone))
299 return -25;
301 return 0;
304 static int
305 test_subkey_path (ACE_Configuration* config)
307 ACE_Configuration_Section_Key root =
308 config->root_section ();
310 ACE_Configuration_Section_Key testsection;
312 if (config->open_section (root,
313 ACE_TEXT ("Software\\ACE\\test"),
315 testsection))
316 return -26;
318 int ret_val = test (config, testsection);
319 if (ret_val)
320 return ret_val;
322 if (config->open_section (root,
323 ACE_TEXT ("Software"),
325 testsection))
326 return -27;
328 if (config->remove_section (testsection,
329 ACE_TEXT ("ACE"),
331 return -28;
333 return 0;
336 static int
337 run_tests (void)
339 int status;
342 // Test import of a legit INI format from a previously-existing file.
343 ACE_Configuration_Heap cf;
344 if ((status = cf.open ()) != 0)
345 ACE_ERROR ((LM_ERROR,
346 ACE_TEXT ("ACE_Configuration_Heap::open returned %d\n"),
347 status));
348 ACE_Ini_ImpExp import (cf);
349 // This one should work...
350 ACE_TCHAR import_file_name [MAXPATHLEN];
351 #if defined (TEST_DIR)
352 ACE_OS::strcpy (import_file_name, TEST_DIR);
353 ACE_OS::strcat (import_file_name, ACE_DIRECTORY_SEPARATOR_STR);
354 ACE_OS::strcat (import_file_name, ACE_TEXT ("Config_Test_Import_1.ini"));
355 #else
356 ACE_OS::strcpy (import_file_name, ACE_TEXT ("Config_Test_Import_1.ini"));
357 #endif
359 status = import.import_config (import_file_name);
360 if (status != 0) {
361 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p: %s\n"),
362 ACE_TEXT ("Config_Test_Import_1.ini failed"),
363 import_file_name));
365 else {
366 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s imported\n"), import_file_name));
368 // Imported clean; verify content. See ini file for expected content.
369 // Verify the expected sections are there, but no others. Verify the
370 // expected keys are there, but no others.
371 int section1_seen = 0, section2_seen = 0;
372 int somekey_seen = 0, someotherkey_seen = 0;
373 int index;
374 ACE_TString sect_name;
375 const ACE_Configuration_Section_Key &root = cf.root_section ();
376 for (index = 0;
377 (status = cf.enumerate_sections (root, index, sect_name)) == 0;
378 ++index) {
379 if (index > 1) // There are only two sections.
380 ACE_ERROR ((LM_ERROR,
381 ACE_TEXT ("Enumerated %d sections; expected 2\n"),
382 index + 1));
383 else {
384 ACE_DEBUG ((LM_DEBUG,
385 ACE_TEXT ("Enumerated to section %s\n"),
386 sect_name.c_str ()));
387 if (sect_name == ACE_TEXT ("SectionOne")) {
388 if (section1_seen)
389 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %s multiple times!\n"),
390 sect_name.c_str ()));
391 section1_seen = 1;
392 // Check for values in this section.
393 ACE_Configuration_Section_Key sect1;
394 if (cf.open_section (root, sect_name.c_str (), 0, sect1) != 0)
395 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to open section: %s\n"),
396 sect_name.c_str ()));
397 else {
398 int val_index = 0, val_status;
399 ACE_TString val_name, value;
400 ACE_Configuration::VALUETYPE val_type;
401 while ((val_status =
402 cf.enumerate_values
403 (sect1, val_index, val_name, val_type)) == 0) {
404 ACE_DEBUG ((LM_DEBUG,
405 ACE_TEXT ("Enumerated %s, type %d\n"),
406 val_name.c_str (),
407 val_type));
408 if (val_type != ACE_Configuration::STRING)
409 ACE_ERROR ((LM_ERROR,
410 ACE_TEXT ("Expected %s to be STRING, but %d\n"),
411 val_name.c_str (),
412 val_type));
413 if (val_name == ACE_TEXT ("SomeKey")) {
414 if (somekey_seen)
415 ACE_ERROR ((LM_ERROR,
416 ACE_TEXT ("Saw %s more than once\n"),
417 val_name.c_str ()));
418 somekey_seen = 1;
420 else
421 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unexpected key %s\n"),
422 val_name.c_str ()));
423 if ((val_status = cf.get_string_value
424 (sect1, val_name.c_str (), value)) != 0)
425 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Can't get value of %s\n"),
426 val_name.c_str ()));
427 else {
428 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s value: %s\n"),
429 val_name.c_str (), value.c_str ()));
430 if (value != ACE_TEXT ("SomeValue")) {
431 ACE_ERROR ((LM_ERROR,
432 ACE_TEXT ("SomeKey: %s; expected SomeValue\n")));
435 ++val_index;
437 if (val_status == 1) {
438 if (val_index != 1) // Should have only seen 1
439 ACE_ERROR ((LM_ERROR,
440 ACE_TEXT ("Expected 1 value; saw %d\n"),
441 index));
443 else
444 ACE_ERROR ((LM_ERROR,
445 ACE_TEXT ("Error enumerating %s; status %d\n"),
446 sect_name.c_str (), val_status));
449 else if (sect_name == ACE_TEXT ("SectionTwo")) {
450 if (section2_seen)
451 ACE_ERROR ((LM_ERROR,
452 ACE_TEXT ("Saw %s multiple times!\n"),
453 sect_name.c_str ()));
454 section2_seen = 1;
455 // Check for values in this section.
456 ACE_Configuration_Section_Key sect2;
457 if (cf.open_section (root, sect_name.c_str (), 0, sect2) != 0)
458 ACE_ERROR ((LM_ERROR,
459 ACE_TEXT ("Failed to open section: %s\n"),
460 sect_name.c_str ()));
461 else {
462 int val_index = 0, val_status;
463 ACE_TString val_name, value;
464 ACE_Configuration::VALUETYPE val_type;
465 while ((val_status = cf.enumerate_values
466 (sect2, val_index, val_name, val_type)) == 0) {
467 ACE_DEBUG ((LM_DEBUG,
468 ACE_TEXT ("Enumerated %s, type %d\n"),
469 val_name.c_str (),
470 val_type));
471 if (val_type != ACE_Configuration::STRING)
472 ACE_ERROR ((LM_ERROR,
473 ACE_TEXT ("Expected %s to be STRING, but %d\n"),
474 val_name.c_str (), val_type));
475 if (val_name == ACE_TEXT ("SomeOtherKey")) {
476 if (someotherkey_seen)
477 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %s more than once\n"),
478 val_name.c_str ()));
479 someotherkey_seen = 1;
481 else
482 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unexpected key %s\n"),
483 val_name.c_str ()));
484 if ((val_status = cf.get_string_value
485 (sect2, val_name.c_str (), value)) != 0)
486 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Can't get value of %s\n"),
487 val_name.c_str ()));
488 else {
489 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s value: %s\n"),
490 val_name.c_str (), value.c_str ()));
491 if (value != ACE_TEXT ("SomeOtherValue")) {
492 ACE_ERROR ((LM_ERROR,
493 ACE_TEXT ("SomeOtherKey: %s; expected SomeOtherValue\n")));
496 ++val_index;
498 if (val_status == 1) {
499 if (val_index != 1) // Should have only seen 1
500 ACE_ERROR ((LM_ERROR,
501 ACE_TEXT ("Expected 1 value; saw %d\n"),
502 index));
504 else
505 ACE_ERROR ((LM_ERROR,
506 ACE_TEXT ("Error enumerating %s; status %d\n"),
507 sect_name.c_str (), val_status));
510 else {
511 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw unexpected section: %s\n"),
512 sect_name.c_str ()));
516 if (status == 1) { // Ran out of sections
517 if (index != 2)
518 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %d sections; expected 2\n"),
519 index));
521 else
522 ACE_ERROR ((LM_ERROR,
523 ACE_TEXT ("Error enumerating sections; status %d\n"),
524 status));
528 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
530 ACE_Configuration_Win32Registry RegConfig (HKEY_LOCAL_MACHINE);
531 int result = test_subkey_path (&RegConfig);
532 if (result)
533 ACE_ERROR_RETURN ((LM_ERROR,
534 ACE_TEXT ("Win32Registry test HKEY_LOCAL_MACHINE")
535 ACE_TEXT (" failed (%d)\n"), result),
536 -1);
538 // test win32 registry implementation.
539 HKEY root =
540 ACE_Configuration_Win32Registry::resolve_key (HKEY_LOCAL_MACHINE,
541 ACE_TEXT ("Software\\ACE\\test"));
542 if (!root)
543 ACE_ERROR_RETURN ((LM_ERROR,
544 ACE_TEXT ("resolve_key is broken\n")), -2);
546 // test resolving of forward slashes
547 HKEY root_fs =
548 ACE_Configuration_Win32Registry::resolve_key (HKEY_LOCAL_MACHINE,
549 ACE_TEXT ("Software/ACE/test"), 0);
550 if (!root_fs)
551 ACE_ERROR_RETURN ((LM_ERROR,
552 ACE_TEXT ("resolve_key resolving slashes is broken\n")),
553 -2);
555 ACE_Configuration_Win32Registry RegConfig (root);
557 int const result = test (&RegConfig);
558 if (result)
559 ACE_ERROR_RETURN ((LM_ERROR,
560 ACE_TEXT ("Win32 registry test root failed (%d)\n"),
561 result),
562 -1);
565 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
567 // Test Heap version
568 ACE_Configuration_Heap heap_config;
570 if (heap_config.open () != 0)
571 ACE_ERROR_RETURN ((LM_ERROR,
572 ACE_TEXT ("Cannot open %p\n"),
573 ACE_TEXT ("local-heap config")),
574 -1);
575 if (heap_config.open () == 0)
577 ACE_ERROR_RETURN ((LM_ERROR,
578 ACE_TEXT ("Re-open heap allowed; bugzilla 3724\n")),
579 -1);
581 else if (errno != EBUSY)
583 ACE_ERROR_RETURN ((LM_ERROR,
584 ACE_TEXT ("Re-open heap expected EBUSY (%d), ")
585 ACE_TEXT ("got %d: bugzilla 3724\n"),
586 EBUSY, ACE_ERRNO_GET),
587 -1);
590 int result = test_subkey_path (&heap_config);
591 if (result)
592 ACE_ERROR_RETURN ((LM_ERROR,
593 ACE_TEXT ("Heap Config subkey test failed (%d)\n"),
594 result),
595 -1);
599 int result = test (&heap_config);
600 if (result)
601 ACE_ERROR_RETURN ((LM_ERROR,
602 ACE_TEXT ("Heap Configuration test failed (%d)\n"),
603 result),
604 -1);
607 #if !defined (ACE_LACKS_MMAP)
608 // Test persistent heap version
609 ACE_OS::unlink (ACE_TEXT ("test.reg"));
610 ACE_Configuration_Heap pers_config;
612 if (pers_config.open (ACE_TEXT ("test.reg")))
613 ACE_ERROR_RETURN ((LM_ERROR,
614 ACE_TEXT ("Cannot open %p\n"),
615 ACE_TEXT ("test.reg")),
616 -1);
617 if (pers_config.open (ACE_TEXT ("test.reg")) == 0)
619 ACE_ERROR_RETURN ((LM_ERROR,
620 ACE_TEXT ("Re-open(mmap) allowed; bugzilla 3724\n")),
621 -1);
623 else if (errno != EBUSY)
625 ACE_ERROR_RETURN ((LM_ERROR,
626 ACE_TEXT ("Re-open(mmap) expected EBUSY (%d), ")
627 ACE_TEXT ("got %d: bugzilla 3724\n"),
628 EBUSY, ACE_ERRNO_GET),
629 -1);
631 if (pers_config.open () == 0)
633 ACE_ERROR_RETURN ((LM_ERROR,
634 ACE_TEXT ("Re-open(new) allowed; bugzilla 3724\n")),
635 -1);
637 else if (errno != EBUSY)
639 ACE_ERROR_RETURN ((LM_ERROR,
640 ACE_TEXT ("Re-open(new) expected EBUSY (%d), ")
641 ACE_TEXT ("got %d: bugzilla 3724\n"),
642 EBUSY, ACE_ERRNO_GET),
643 -1);
647 int result = test (&pers_config);
648 if (result)
649 ACE_ERROR_RETURN ((LM_ERROR,
650 ACE_TEXT ("Persistent Heap Config test failed (%d)\n"),
651 result),
652 -1);
654 #endif /* !ACE_LACKS_MMAP */
656 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Test passed\n")));
657 return 0;
660 static int
661 build_config_object (ACE_Configuration& cfg)
663 ACE_Configuration_Section_Key root = cfg.root_section ();
664 ACE_Configuration_Section_Key NetworkSection;
665 ACE_Configuration_Section_Key LoggerSection;
666 ACE_Configuration_Section_Key BinarySection;
668 if (cfg.open_section (root,
669 ACE_TEXT ("network"),
671 NetworkSection))
672 return -1;
674 if (cfg.set_integer_value (NetworkSection,
675 ACE_TEXT ("TimeToLive"),
676 100))
677 return -2;
678 else if (cfg.set_string_value (NetworkSection,
679 ACE_TEXT ("Delay"),
680 ACE_TString (ACE_TEXT ("FALSE"))))
681 return -3;
682 else if (cfg.set_string_value (NetworkSection,
683 ACE_TEXT ("DestIPAddress"),
684 ACE_TString (ACE_TEXT ("localhost"))))
685 return -4;
686 else if (cfg.set_integer_value (NetworkSection,
687 ACE_TEXT ("DestPort"),
688 12670))
689 return -5;
690 else if (cfg.set_integer_value (NetworkSection,
691 ACE_TEXT ("ReconnectInterval"),
693 return -6;
695 if (cfg.open_section (root,
696 ACE_TEXT ("logger"),
698 LoggerSection))
699 return -7;
701 if (cfg.set_string_value (LoggerSection,
702 ACE_TEXT ("Heading"),
703 ACE_TString (ACE_TEXT ("ACE - Adaptive Communication Environment"))))
704 return -8;
705 else if (cfg.set_integer_value (LoggerSection,
706 ACE_TEXT ("SeekIndex"),
707 14))
708 return -9;
709 else if (cfg.set_integer_value (LoggerSection,
710 ACE_TEXT ("TraceLevel"),
712 return -10;
713 else if (cfg.set_string_value (LoggerSection,
714 ACE_TEXT ("Justification"),
715 ACE_TString (ACE_TEXT ("left_justified"))))
716 return -11;
717 else if (cfg.set_string_value (LoggerSection,
718 ACE_TEXT ("LogFilePath"),
719 ACE_TString (ACE_TEXT ("log/"))))
720 return -12;
721 else if (cfg.set_string_value (LoggerSection,
722 ACE_TEXT ("TransactionFilePath"),
723 ACE_TString (ACE_TEXT ("data/"))))
724 return -13;
726 if (cfg.open_section (root,
727 ACE_TEXT ("binary"),
729 BinarySection))
730 return -14;
732 u_char data[80];
734 for (int i = 0; i < 80; i++)
735 data[i] = i + 128;
737 if (cfg.set_binary_value (BinarySection,
738 ACE_TEXT ("data"),
739 data,
740 80))
741 return -15;
743 ACE_TString string((ACE_TCHAR*) 0);// = '0';
744 // Try to set the unnamed, default value.
745 if (cfg.set_string_value (LoggerSection,
746 0,//string.c_str (),//0, //ACE_TEXT ("x"),
747 ACE_TString (ACE_TEXT ("some string"))))
748 ACE_ERROR_RETURN ((LM_ERROR,
749 ACE_TEXT ("could not set value with null name\n")),
750 -16);
752 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("here\n")));
753 //return 0;
754 //ACE_TString string;
755 ACE_TString name ((ACE_TCHAR*)0);
756 if (cfg.get_string_value (LoggerSection,
757 name.c_str (), //0, //ACE_TEXT ("x"),
758 string))
759 ACE_ERROR_RETURN ((LM_ERROR,
760 ACE_TEXT ("error using ACE_TString::c_str() == %d, len == %d\n"),
761 name.c_str(), name.length ()),
762 -17);
764 ACE_DEBUG ((LM_DEBUG,
765 ACE_TEXT ("the value for the unnamed var=(%s)\n"),
766 string.c_str ()));
768 return 0;
772 * Test ACE_Configuration::operator==
775 Config_Test::testEquality ()
777 // create and open 2 ACE_Configuration objects.
778 ACE_Configuration_Heap heap1;
779 ACE_Configuration_Heap heap2;
780 if ((heap1.open ()) != 0)
782 ACE_ERROR_RETURN ((LM_ERROR,
783 ACE_TEXT ("Cannot open heap1\n")),
784 -1);
787 else if ((heap2.open ()) != 0)
789 ACE_ERROR_RETURN ((LM_ERROR,
790 ACE_TEXT ("Cannot open heap2\n")),
791 -1);
794 // populate them equally
795 if (build_config_object (heap1) != 0 ||
796 build_config_object (heap2) != 0)
797 ACE_ERROR_RETURN ((LM_ERROR,
798 ACE_TEXT ("could not build config object\n")),
799 -1);
801 // test equality
802 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should equal...\n")));
803 if (heap1 == heap2)
805 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do ;-)\n")));
807 else
809 ACE_ERROR_RETURN ((LM_ERROR,
810 ACE_TEXT ("And they do not :-(\n")
811 ACE_TEXT ("operator== Failed when objects equal\n")),
812 -1);
815 // add a section and value to heap1
816 ACE_Configuration_Section_Key root1 = heap1.root_section ();
817 ACE_Configuration_Section_Key NewSection;
818 if (heap1.open_section (root1,
819 ACE_TEXT ("NewSection"),
821 NewSection))
822 ACE_ERROR_RETURN ((LM_ERROR,
823 ACE_TEXT ("Error adding section to heap1\n")),
824 -1);
825 else if (heap1.set_integer_value (NewSection,
826 ACE_TEXT ("TestIntValue"),
827 100))
828 ACE_ERROR_RETURN ((LM_ERROR,
829 ACE_TEXT ("Error adding value to heap1\n")),
830 -2);
832 // test equality
833 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
834 if (heap1 == heap2)
835 ACE_ERROR_RETURN ((LM_ERROR,
836 ACE_TEXT ("They Do :-(\noperator== Failed ")
837 ACE_TEXT ("when lhs contains data not in rhs\n")),
838 -1);
839 else
840 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not ;-)\n")));
843 // add same section to heap2
845 ACE_Configuration_Section_Key root2 = heap2.root_section ();
846 ACE_Configuration_Section_Key NewSection2;
847 if (heap2.open_section (root2,
848 ACE_TEXT ("NewSection"),
850 NewSection2))
851 ACE_ERROR_RETURN ((LM_ERROR,
852 ACE_TEXT ("Error adding section to heap2\n")),
853 -1);
854 else if (heap2.set_integer_value (NewSection2,
855 ACE_TEXT ("TestIntValue"),
856 100))
857 ACE_ERROR_RETURN ((LM_ERROR,
858 ACE_TEXT ("Error adding value to heap2\n")),
859 -2);
860 else if (heap2.set_integer_value (NewSection2,
861 ACE_TEXT ("TestIntValue2"),
862 100))
863 ACE_ERROR_RETURN ((LM_ERROR,
864 ACE_TEXT ("Error adding second value to heap2\n")),
865 -2);
867 // test equality
868 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
869 if (heap1 == heap2)
870 ACE_ERROR_RETURN ((LM_ERROR,
871 ACE_TEXT ("And They Do :-(\noperator== Failed ")
872 ACE_TEXT ("when rhs contains value not in lhs\n")),
873 -1);
874 else
875 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not ;-)\n")));
877 // add new value in heap 1
878 if (heap1.set_integer_value (NewSection,
879 ACE_TEXT ("TestIntValue2"),
880 100))
881 ACE_ERROR_RETURN ((LM_ERROR,
882 ACE_TEXT ("Error adding second value to heap1\n")),
883 -2);
885 // test equality
886 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should be equal...\n")));
887 if (heap1 == heap2)
888 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they are ;-)\n")));
889 else
890 ACE_ERROR_RETURN ((LM_ERROR,
891 ACE_TEXT ("And they are not :-(\n")
892 ACE_TEXT ("operator== Failed\n")),
893 -1);
895 // Add a new section to heap2
896 ACE_Configuration_Section_Key AnotherNewSection2;
897 if (heap2.open_section (root2,
898 ACE_TEXT ("AnotherNewSection"),
900 AnotherNewSection2))
901 ACE_ERROR_RETURN ((LM_ERROR,
902 ACE_TEXT ("Error adding second section to heap2\n")),
903 -1);
904 else if (heap2.set_integer_value (AnotherNewSection2,
905 ACE_TEXT ("TestIntValue"),
906 100))
907 ACE_ERROR_RETURN ((LM_ERROR,
908 ACE_TEXT ("Error adding value in second section")
909 ACE_TEXT (" to heap2\n")),
910 -2);
912 // test equality
913 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
914 if (heap1 == heap2)
915 ACE_ERROR_RETURN ((LM_ERROR,
916 ACE_TEXT ("And they do :-(\noperator== Failed ")
917 ACE_TEXT ("when rhs contains data not in lhs\n")),
918 -1);
919 else
920 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not :-)\n")));
922 // add section back to heap1
923 ACE_Configuration_Section_Key AnotherNewSection1;
924 if (heap1.open_section (root1,
925 ACE_TEXT ("AnotherNewSection"),
927 AnotherNewSection1))
928 ACE_ERROR_RETURN ((LM_ERROR,
929 ACE_TEXT ("Error adding second section to heap1\n")),
930 -1);
931 else if (heap1.set_integer_value (AnotherNewSection1,
932 ACE_TEXT ("TestIntValue"),
933 100))
934 ACE_ERROR_RETURN ((LM_ERROR,
935 ACE_TEXT ("Error adding second value to second ")
936 ACE_TEXT ("section in heap1\n")),
937 -2);
939 // test equality
940 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should be equal...\n")));
941 if (heap1 == heap2)
942 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they are ;-)\n")));
943 else
944 ACE_ERROR_RETURN ((LM_ERROR,
945 ACE_TEXT ("And they are not :-(\n")
946 ACE_TEXT ("operator== Failed\n")),
947 -1);
949 this->equality_tested_ = 1;
950 return 0;
954 * Compare INI import data in fromFile to origional data exported (in origional)
956 * This compare is destructive to the origional object.
957 * I realize that normally you would not do such an obscene thing but
958 * this funciton has a special purpose and I know my origional is not needed
959 * after calling this routine.
960 * This is done because configuration objects that are imported using the INI
961 * import store all data as strings. My origional has type information and I need to
962 * know if the import worked.
964 static int
965 iniCompare (ACE_Configuration_Heap& fromFile, ACE_Configuration_Heap& original)
967 bool rc = true; // start by guessing they are equal
969 int sectionIndex = 0;
970 ACE_TString sectionName;
972 const ACE_Configuration_Section_Key& fromFileRoot = fromFile.root_section ();
973 const ACE_Configuration_Section_Key& originalRoot = original.root_section ();
974 ACE_Configuration_Section_Key originalSection;
975 ACE_Configuration_Section_Key fromFileSection;
977 // loop through each section in the fromFile object
978 while ((rc) &&
979 (!fromFile.enumerate_sections (fromFileRoot,
980 sectionIndex,
981 sectionName)) )
983 // find that section in the original object
984 if (original.open_section (originalRoot,
985 sectionName.c_str (),
987 originalSection) != 0)
988 // If the original object does not contain the section then we
989 // are not equal.
990 rc = false;
991 else if (fromFile.open_section (fromFileRoot,
992 sectionName.c_str (),
994 fromFileSection) != 0)
995 // if there is some error opening the section in the fromFile
996 rc = false;
997 else
999 // Well the sections match
1000 int valueIndex = 0;
1001 ACE_TString valueName;
1002 ACE_Configuration::VALUETYPE valueType;
1003 ACE_Configuration::VALUETYPE originalType;
1005 // Enumerate each value in the fromFile section
1006 while ((rc) &&
1007 (!fromFile.enumerate_values (fromFileSection,
1008 valueIndex,
1009 valueName,
1010 valueType)))
1012 // look for the same value in the original section
1013 if (original.find_value (originalSection,
1014 valueName.c_str (),
1015 originalType) != 0)
1016 // We're not equal if the same value cannot be found
1017 // in the original object.
1018 rc = false;
1019 else
1021 ACE_TString fromFileString, originalString;
1024 if (fromFile.get_string_value (fromFileSection,
1025 valueName.c_str (),
1026 fromFileString) != 0)
1027 // we're not equal if we cannot get this string
1028 rc = false;
1029 else if (originalType != ACE_Configuration::STRING) // If the original type is not a string
1031 // convert original data to a string.
1033 if (originalType == ACE_Configuration::INTEGER)
1035 u_int intValue;
1036 ACE_TCHAR int_value[32];
1038 if (original.get_integer_value (originalSection,
1039 valueName.c_str (),
1040 intValue) != 0)
1041 // we're not equal if we cannot get rhs int
1042 rc = false;
1044 ACE_OS::snprintf (int_value, 32, ACE_TEXT ("%08x"),
1045 intValue);
1046 originalString = int_value;
1048 else if (originalType == ACE_Configuration::BINARY)
1050 void* binary_data;
1051 size_t binary_length;
1053 if (original.get_binary_value (originalSection,
1054 valueName.c_str (),
1055 binary_data,
1056 binary_length))
1057 // we're not equal if we cannot get this string
1058 rc = false;
1059 else
1061 ACE_TCHAR bin_value[3];
1063 unsigned char* ptr = (unsigned char*)binary_data;
1064 while (binary_length)
1066 if (ptr != binary_data)
1067 originalString += ACE_TEXT (",");
1069 ACE_OS::snprintf (bin_value, 3,
1070 ACE_TEXT ("%02x"),
1071 *ptr);
1072 originalString += bin_value;
1073 --binary_length;
1074 ++ptr;
1076 delete [] (char *)binary_data;
1077 }// end successful binary read
1078 }// end if originalType was binary
1079 else
1080 // if the type is invalid, then go ahead and fail it.
1081 rc = false;
1083 }// end if the original type was not a string.
1084 else
1086 if (original.get_string_value (originalSection,
1087 valueName.c_str (),
1088 originalString) != 0)
1090 // we're not equal if we cannot get rhs string
1091 rc = false;
1096 rc &= fromFileString == originalString;
1098 if (rc)
1099 // before we move on remove this value from the original.
1100 original.remove_value (originalSection,
1101 valueName.c_str ());
1103 }// end else if values match.
1105 valueIndex++;
1107 }// end value while loop
1109 // at this point the original should have no values. look
1110 // for values in the original section
1111 valueIndex = 0;
1112 while ((rc) &&
1113 (!original.enumerate_values (originalSection,
1114 valueIndex,
1115 valueName,
1116 originalType)))
1117 valueIndex++;
1119 // having a value indicates a mismatch
1120 rc = valueIndex == 0;
1122 }// end else if sections match.
1124 if (rc)
1125 // before we move on remove the section from the original.
1126 original.remove_section (originalRoot,
1127 sectionName.c_str (),
1128 0); // do not remove subsections.
1130 ++sectionIndex;
1132 }// end section while loop
1134 // Finally, if the original has any sections, then we're not equal
1135 sectionIndex = 0;
1136 while ((rc) &&
1137 (!original.enumerate_sections (originalRoot,
1138 sectionIndex,
1139 sectionName)))
1140 ++sectionIndex;
1142 rc = sectionIndex == 0;
1144 return rc;
1147 // change a network section value
1148 int Config_Test::change_one (ACE_Configuration &cfg, u_int a)
1150 ACE_Configuration_Section_Key root = cfg.root_section ();
1151 ACE_Configuration_Section_Key NetworkSection;
1152 ACE_Configuration_Section_Key LoggerSection;
1153 ACE_Configuration_Section_Key BinarySection;
1155 if (cfg.open_section (root,
1156 ACE_TEXT ("network"),
1158 NetworkSection))
1159 return -1;
1161 if (cfg.set_integer_value (NetworkSection,
1162 ACE_TEXT ("TimeToLive"),
1164 return -2;
1166 return 0;
1169 // Used to test INI Import Export class
1172 Config_Test::testIniFormat ()
1174 int rc = 0;
1175 if (!this->equality_tested_)
1177 rc = this->testEquality ();
1178 if (rc != 0)
1180 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Equality Test Failed\n")));
1181 return rc;
1185 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing INI Format Import/Export\n")));
1186 ACE_Configuration_Heap fromFile;
1188 // 1. Creates an ACE_Configuration_Heap object
1189 ACE_Configuration_Heap original;
1191 rc = original.open ();
1192 if (rc == 0)
1194 rc = build_config_object (original);
1195 // 2. Calls build_config_object to populate
1196 if (rc != 0)
1197 ACE_ERROR_RETURN ((LM_ERROR,
1198 ACE_TEXT ("Error populating original config ")
1199 ACE_TEXT ("object (%d)\n"),
1200 rc),
1201 -1);
1202 // 3. Export
1203 ACE_Ini_ImpExp importExport (original);
1205 rc = importExport.export_config (ACE_TEXT ("testConfig.ini"));
1206 if (rc != 0)
1207 ACE_ERROR_RETURN ((LM_ERROR,
1208 ACE_TEXT ("Error Exporting (%d)\n"),
1209 rc),
1210 -1);
1212 else
1213 ACE_ERROR_RETURN ((LM_ERROR,
1214 ACE_TEXT ("Could not open original object (%d)\n"),
1215 rc),
1216 -1);
1218 // At this point we've successfully created, populated and written
1219 // the configuration object
1220 // 5. Creates a new ACE_Configuration_Heap object
1221 rc = fromFile.open ();
1222 if (rc == 0)
1224 // 6. Imports
1225 ACE_Ini_ImpExp importExport (fromFile);
1227 rc = importExport.import_config (ACE_TEXT ("testConfig.ini"));
1228 if (rc != 0)
1229 ACE_ERROR_RETURN ((LM_ERROR,
1230 ACE_TEXT ("Error Exporting (%d)\n"),
1231 rc),
1232 -1);
1234 // 7. Compares to original.
1235 // This is a special compare since files imported using the
1236 // INI file import do not contain type information
1238 // NOTE: After this call the original object will be invalid!!!
1240 if (!iniCompare (fromFile, original))
1241 ACE_ERROR_RETURN ((LM_ERROR,
1242 ACE_TEXT ("Object read from file does not ")
1243 ACE_TEXT ("equal original (%d)\n"),
1244 rc),
1245 -1);
1246 }// end if heap could not be opened.
1247 else
1248 ACE_ERROR_RETURN ((LM_ERROR,
1249 ACE_TEXT ("Could not open fromFile object (%d)\n"),
1250 rc),
1251 -1);
1253 // 8. Calls old "read_config" methods on the new object
1255 int nTimeToLive;
1256 int bDelay;
1257 int nDestPort;
1258 int nReconnectInterval;
1259 int nTraceLevel;
1261 ACE_TCHAR pszDestIPAddress[TEST_MAX_STRING];
1262 ACE_TCHAR pszLogFilePath[TEST_MAX_STRING];
1263 ACE_TCHAR pszTransactionFilePath[TEST_MAX_STRING];
1264 ACE_TCHAR pszHeading[TEST_MAX_STRING];
1265 ACE_TCHAR pszJustification[TEST_MAX_STRING];
1267 ACE_Configuration_Section_Key root = fromFile.root_section ();
1269 // Process [network] section
1270 ACE_Configuration_Section_Key NetworkSection;
1271 if (fromFile.open_section (root,
1272 ACE_TEXT ("network"),
1274 NetworkSection) == 0)
1276 this->get_section_integer (fromFile,
1277 NetworkSection,
1278 ACE_TEXT ("TimeToLive"),
1279 &nTimeToLive,
1281 20);
1283 this->get_section_boolean (fromFile,
1284 NetworkSection,
1285 ACE_TEXT ("Delay"),
1286 &bDelay);
1288 this->get_section_string (fromFile,
1289 NetworkSection,
1290 ACE_TEXT ("DestIPAddress"),
1291 pszDestIPAddress,
1292 TEST_MAX_STRING);
1294 this->get_section_integer (fromFile,
1295 NetworkSection,
1296 ACE_TEXT ("DestPort"),
1297 &nDestPort,
1299 65535);
1301 this->get_section_integer (fromFile,
1302 NetworkSection,
1303 ACE_TEXT ("ReconnectInterval"),
1304 &nReconnectInterval,
1306 65535);
1307 }// end of "network" section
1309 // Process [logger] section
1310 ACE_Configuration_Section_Key LoggerSection;
1311 if (fromFile.open_section (root,
1312 ACE_TEXT ("logger"),
1314 LoggerSection) == 0)
1316 this->get_section_string (fromFile,
1317 LoggerSection,
1318 ACE_TEXT ("Heading"),
1319 pszHeading,
1320 TEST_MAX_STRING);
1321 this->get_section_integer (fromFile,
1322 LoggerSection,
1323 ACE_TEXT ("TraceLevel"),
1324 &nTraceLevel,
1326 20);
1327 this->get_section_string (fromFile,
1328 LoggerSection,
1329 ACE_TEXT ("Justification"),
1330 pszJustification,
1331 TEST_MAX_STRING);
1332 this->get_section_string (fromFile,
1333 LoggerSection,
1334 ACE_TEXT ("LogFilePath"),
1335 pszLogFilePath,
1336 TEST_MAX_STRING);
1337 this->get_section_string (fromFile,
1338 LoggerSection,
1339 ACE_TEXT ("TransactionFilePath"),
1340 pszTransactionFilePath,
1341 TEST_MAX_STRING);
1342 }// end of "logger" section
1344 if (!rc)
1345 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("INI Format Import/Export Works ;-)\n")));
1346 return rc;
1349 // Used to test registry Import Export class
1352 Config_Test::testRegFormat ()
1354 int rc = 0;
1355 if (!this->equality_tested_)
1357 rc = this->testEquality ();
1358 if (rc != 0)
1360 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Equality Test Failed\n")));
1361 return rc;
1365 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing Registry Format Import/Export\n")));
1366 ACE_Configuration_Heap fromFile;
1368 // 1. Creates an ACE_Configuration_Heap object
1369 ACE_Configuration_Heap original;
1371 rc = original.open ();
1372 if (rc == 0)
1374 // 2. Calls build_config_object to populate
1375 rc = build_config_object (original);
1376 if (rc != 0)
1377 ACE_ERROR_RETURN ((LM_ERROR,
1378 ACE_TEXT ("Error populating original config ")
1379 ACE_TEXT ("object (%d)\n"),
1380 rc),
1381 -1);
1382 // 3. Export
1383 ACE_Registry_ImpExp importExport (original);
1385 rc = importExport.export_config (ACE_TEXT ("testConfig.ini"));
1386 if (rc != 0)
1387 ACE_ERROR_RETURN ((LM_ERROR,
1388 ACE_TEXT ("Error Exporting (%d)\n"),
1389 rc),
1390 -1);
1392 else
1393 ACE_ERROR_RETURN ((LM_ERROR,
1394 ACE_TEXT ("Could not open original object (%d)\n"),
1395 rc),
1396 -1);
1398 // At this point we've successfully created, populated and written
1399 // the configuration object
1400 // 5. Creates a new ACE_Configuration_Heap object
1401 rc = fromFile.open ();
1402 if (rc == 0)
1404 // 6. Imports
1405 ACE_Registry_ImpExp importExport (fromFile);
1407 rc = importExport.import_config (ACE_TEXT ("testConfig.ini"));
1408 if (rc != 0)
1409 ACE_ERROR_RETURN ((LM_ERROR,
1410 ACE_TEXT("Error Exporting (%d)\n"),
1411 rc),
1412 -1);
1414 // 7. Compares to original.
1415 if (fromFile != original)
1416 ACE_ERROR_RETURN ((LM_ERROR,
1417 ACE_TEXT ("Object read from file does not ")
1418 ACE_TEXT ("equal original (%d)\n"),
1419 rc),
1420 -1);
1422 // 7.1 Change a value and test NOT equal case
1423 change_one (original, 101);
1424 if (fromFile == original)
1426 ACE_ERROR_RETURN ((LM_ERROR,
1427 ACE_TEXT ("not pass value change test (%d)\n"),
1428 rc),
1429 -1);
1432 // 7.2 change value back, they should be equal now
1433 change_one (original, 100);
1434 if (fromFile != original)
1436 ACE_ERROR_RETURN ((LM_ERROR,
1437 ACE_TEXT ("not pass value change test (%d)\n"),
1438 rc),
1439 -1);
1442 }// end if heap could not be opened.
1443 else
1444 ACE_ERROR_RETURN ((LM_ERROR,
1445 ACE_TEXT ("Could not open fromFile object (%d)\n"),
1446 rc),
1447 -1);
1449 if (!rc)
1450 ACE_DEBUG ((LM_DEBUG,
1451 ACE_TEXT ("Registry Format Import/Export Works ;-)\n")));
1452 return rc;
1456 // Reads a string value from a configuration object.
1458 void
1459 Config_Test::get_section_string (ACE_Configuration& config,
1460 ACE_Configuration_Section_Key& SectionKey,
1461 const ACE_TCHAR* pszName,
1462 ACE_TCHAR* pszVariable,
1463 int nMaxLength)
1465 ACE_TString StringValue;
1467 if (config.get_string_value (SectionKey,
1468 pszName,
1469 StringValue) == 0)
1471 ACE_OS::strncpy (pszVariable,
1472 StringValue.c_str (),
1473 nMaxLength);
1474 ACE_DEBUG ((LM_DEBUG,
1475 ACE_TEXT ("%s = %s\n"),
1476 pszName,
1477 pszVariable));
1481 // Reads an integer value from a configuration object (when it's
1482 // stored as a string)
1483 void
1484 Config_Test::get_section_integer (ACE_Configuration& config,
1485 ACE_Configuration_Section_Key& SectionKey,
1486 const ACE_TCHAR* pszName,
1487 int* nVariable,
1488 int nMinValue,
1489 int nMaxValue)
1491 ACE_TString StringValue;
1492 ACE_TCHAR pszString[30];
1493 ACE_OS::strcpy (pszString, ACE_TEXT ("0"));
1494 int IntegerValue = 0;
1496 if (config.get_string_value (SectionKey,
1497 pszName,
1498 StringValue) == 0)
1500 ACE_OS::strncpy (pszString,
1501 StringValue.c_str (),
1502 30);
1503 ACE_DEBUG ((LM_DEBUG,
1504 ACE_TEXT ("%s = %s\n"),
1505 pszName,
1506 pszString));
1509 // convert to integer
1510 IntegerValue = ACE_OS::atoi (pszString);
1511 IntegerValue = (IntegerValue < nMinValue) ? nMinValue : IntegerValue;
1512 IntegerValue = (IntegerValue > nMaxValue) ? nMaxValue : IntegerValue;
1513 *nVariable = IntegerValue;
1516 // Reads a boolean value from a configuration object (when it's stored as a string).
1518 void
1519 Config_Test::get_section_boolean (ACE_Configuration& config,
1520 ACE_Configuration_Section_Key& SectionKey,
1521 const ACE_TCHAR* pszName,
1522 int* pVariable)
1524 ACE_TString StringValue;
1525 ACE_TCHAR pszString[10];
1526 ACE_OS::strcpy (pszString, ACE_TEXT ("0"));
1528 if (config.get_string_value (SectionKey,
1529 pszName,
1530 StringValue) == 0)
1532 ACE_OS::strncpy (pszString,
1533 StringValue.c_str (),
1534 10);
1535 for (ACE_TCHAR* pSrc = pszString;
1536 *pSrc != ACE_TEXT ('\0');
1537 pSrc++)
1538 // Convert to uppercase
1539 if (ACE_OS::ace_islower (*pSrc))
1540 *pSrc = ACE_OS::ace_tolower (*pSrc);
1542 ACE_DEBUG ((LM_DEBUG,
1543 ACE_TEXT ("%s = %s\n"),
1544 pszName,
1545 pszString));
1547 if (ACE_OS::strcmp (pszString,
1548 ACE_TEXT ("TRUE")) == 0)
1549 *pVariable = 1;
1550 else if (ACE_OS::strcmp (pszString,
1551 ACE_TEXT ("FALSE")) == 0)
1552 *pVariable = 0;
1557 run_main (int, ACE_TCHAR *[])
1559 ACE_START_TEST (ACE_TEXT ("Config_Test"));
1560 int errors = 0;
1561 Config_Test manager;
1563 if ((errors += manager.testEquality ()) != 0)
1564 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the equality Test\n")));
1566 if ((errors += manager.testRegFormat ()) != 0)
1567 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the REG Format Test\n")));
1569 if ((errors += manager.testIniFormat ()) != 0)
1570 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the INI Format Test\n")));
1572 if ((errors += run_tests ()) != 0)
1573 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed in run_tests\n")));
1575 ACE_END_TEST;
1576 return errors == 0 ? 0 : 1;