Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / tests / Config_Test.cpp
blobe16932db307e505cbd458a48e10022d29a4cb5d2
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"
25 static int
26 test (ACE_Configuration *config,
27 ACE_Configuration_Section_Key &testsection)
29 ACE_TString stvalue;
31 // Set some values.
32 if (config->set_string_value (testsection,
33 ACE_TEXT ("stvalue"),
34 ACE_TEXT ("stvaluetest")))
35 return -3;
37 else if (config->remove_value (testsection,
38 ACE_TEXT ("stvalue")))
39 return -4;
40 // Make sure it's really gone
41 else if (0 == config->get_string_value (testsection,
42 ACE_TEXT ("stvalue"),
43 stvalue))
44 ACE_ERROR_RETURN ((LM_ERROR,
45 ACE_TEXT ("test:remove_value didn't remove\n")),
46 -4);
48 else if (config->set_string_value (testsection,
49 ACE_TEXT ("stvalue"),
50 ACE_TEXT ("stvaluetest")))
51 return -3;
52 else if (config->set_string_value (testsection,
53 ACE_TEXT ("stvalue"),
54 ACE_TEXT ("second stvaluetest")))
55 ACE_ERROR_RETURN ((LM_ERROR,
56 ACE_TEXT ("test:set_string_value twice failed\n")),
57 -3);
59 else if (config->set_integer_value (testsection,
60 ACE_TEXT ("intvalue"),
61 77))
62 return -4;
63 // Reset to the value we test for below
64 else if (config->set_integer_value (testsection,
65 ACE_TEXT ("intvalue"),
66 42))
67 return -4;
69 static size_t const data_len = 80;
70 u_char data[data_len];
72 for (size_t i = 0; i < data_len ; ++i)
73 data[i] = static_cast<u_char> (i + 128);
75 if (config->set_binary_value (testsection,
76 ACE_TEXT ("binvalue"),
77 data,
78 data_len))
79 return -5;
81 // Get the values and compare
82 if (config->get_string_value (testsection,
83 ACE_TEXT ("stvalue"),
84 stvalue))
85 return -6;
86 else if (stvalue != ACE_TEXT ("second stvaluetest"))
87 return -7;
89 u_int intvalue;
91 if (config->get_integer_value (testsection,
92 ACE_TEXT ("intvalue"),
93 intvalue))
94 return -8;
95 else if (intvalue != 42)
96 return -9;
98 u_char *data_out (0);
101 void *data_tmp = 0; // Workaround for GCC strict aliasing warning.
102 size_t length = 0;
104 if (config->get_binary_value (testsection,
105 ACE_TEXT ("binvalue"),
106 data_tmp,
107 length))
108 return -10;
110 data_out = reinterpret_cast <u_char *> (data_tmp);
113 u_char * the_data = static_cast<u_char *> (data_out);
115 // compare em
116 for (size_t j = 0; j < data_len; ++j)
117 if (the_data[j] != data[j])
118 return -11;
120 delete [] the_data;
122 // Test iteration.
123 ACE_TString name;
124 ACE_Configuration::VALUETYPE type;
125 u_int index = 0;
126 int found[3] = { 0, 0, 0 }; // One for each expected value
128 while (!config->enumerate_values (testsection,
129 index,
130 name,
131 type))
133 if (name == ACE_TEXT ("stvalue"))
135 if (type != ACE_Configuration::STRING)
136 return -12;
137 if (found[0] != 0)
138 return -12;
139 found[0] = 1;
141 else if (name == ACE_TEXT ("intvalue"))
143 if (type != ACE_Configuration::INTEGER)
144 return -13;
145 if (found[1] != 0)
146 return -13;
147 found[1] = 1;
149 else if (name == ACE_TEXT ("binvalue"))
151 if (type != ACE_Configuration::BINARY)
152 return -14;
153 if (found[2] != 0)
154 return -14;
155 found[2] = 1;
157 index++;
160 // Make sure we got three values.
161 if (index != 3 || !found[0] || !found[1] || !found[2])
162 return -15;
165 // Add some subsections. This part is a separate scope to be sure
166 // the test2, test3, test4 keys are closed before further
167 // manipulating/deleting the sections further down in the test.
168 ACE_Configuration_Section_Key test2;
169 ACE_Configuration_Section_Key test3;
170 ACE_Configuration_Section_Key test4;
172 if (config->open_section (testsection,
173 ACE_TEXT ("test2"),
175 test2))
176 return -16;
177 else if (config->open_section (testsection,
178 ACE_TEXT ("test3"),
180 test3))
181 return -17;
182 else if (config->open_section (testsection,
183 ACE_TEXT ("test4"),
185 test4))
186 return -18;
189 // Test enumerate sections.
190 index = 0;
191 found[0] = found[1] = found[2] = 0;
192 while (!config->enumerate_sections (testsection,
193 index,
194 name))
196 if (name == ACE_TEXT ("test2"))
198 if (found[0] != 0)
199 ACE_ERROR_RETURN ((LM_ERROR,
200 ACE_TEXT ("enumerate_sections, dupl test2\n")),
201 -19);
202 found[0] = 1;
204 else if (name == ACE_TEXT ("test3"))
206 if (found[1] != 0)
207 ACE_ERROR_RETURN ((LM_ERROR,
208 ACE_TEXT ("enumerate_sections, dupl test3\n")),
209 -19);
210 found[1] = 1;
212 else if (name == ACE_TEXT ("test4"))
214 if (found[2] != 0)
215 ACE_ERROR_RETURN ((LM_ERROR,
216 ACE_TEXT ("enumerate_sections, dupl test4\n")),
217 -19);
218 found[2] = 1;
220 index++;
223 if (index != 3 || !found[0] || !found[1] || !found[2])
224 return -19;
226 // Remove a subsection
227 if (config->remove_section (testsection,
228 ACE_TEXT ("test2"),
230 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p (%d)\n"),
231 ACE_TEXT ("remove_section test2"),
232 ACE_OS::last_error ()),
233 -20);
235 // Try to remove it again
236 if (!config->remove_section (testsection,
237 ACE_TEXT ("test2"),
239 return -21;
241 return 0;
244 static int
245 test (ACE_Configuration *config)
247 const ACE_Configuration_Section_Key& root =
248 config->root_section ();
251 // Scope this so the testsection key is closed before trying to
252 // remove the "test" section.
253 ACE_Configuration_Section_Key testsection;
255 if (config->open_section (root,
256 ACE_TEXT ("test"),
258 testsection))
259 return -2;
261 int ret_val = test (config, testsection);
262 if (ret_val)
263 return ret_val;
266 // Try to remove the testsection root, it should fail since it still
267 // has subkeys
268 if (!config->remove_section (root,
269 ACE_TEXT ("test"),
271 return -22;
274 // Test find section, and be sure the key is closed before testing the
275 // remove, below.
276 ACE_Configuration_Section_Key result;
278 if (config->open_section (root,
279 ACE_TEXT ("test"),
281 result))
282 return -23;
285 // Now test the recursive remove.
286 if (config->remove_section (root,
287 ACE_TEXT ("test"),
289 return -24;
291 // Make sure its not there
292 ACE_Configuration_Section_Key testsectiongone;
293 if (!config->open_section (root,
294 ACE_TEXT ("test"),
296 testsectiongone))
297 return -25;
299 return 0;
302 static int
303 test_subkey_path (ACE_Configuration* config)
305 ACE_Configuration_Section_Key root =
306 config->root_section ();
308 ACE_Configuration_Section_Key testsection;
310 if (config->open_section (root,
311 ACE_TEXT ("Software\\ACE\\test"),
313 testsection))
314 return -26;
316 int ret_val = test (config, testsection);
317 if (ret_val)
318 return ret_val;
320 if (config->open_section (root,
321 ACE_TEXT ("Software"),
323 testsection))
324 return -27;
326 if (config->remove_section (testsection,
327 ACE_TEXT ("ACE"),
329 return -28;
331 return 0;
334 static int
335 run_tests ()
337 int status;
340 // Test import of a legit INI format from a previously-existing file.
341 ACE_Configuration_Heap cf;
342 if ((status = cf.open ()) != 0)
343 ACE_ERROR ((LM_ERROR,
344 ACE_TEXT ("ACE_Configuration_Heap::open returned %d\n"),
345 status));
346 ACE_Ini_ImpExp import (cf);
347 // This one should work...
348 ACE_TCHAR import_file_name [MAXPATHLEN];
349 #if defined (TEST_DIR)
350 ACE_OS::strcpy (import_file_name, TEST_DIR);
351 ACE_OS::strcat (import_file_name, ACE_DIRECTORY_SEPARATOR_STR);
352 ACE_OS::strcat (import_file_name, ACE_TEXT ("Config_Test_Import_1.ini"));
353 #else
354 ACE_OS::strcpy (import_file_name, ACE_TEXT ("Config_Test_Import_1.ini"));
355 #endif
357 status = import.import_config (import_file_name);
358 if (status != 0) {
359 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p: %s\n"),
360 ACE_TEXT ("Config_Test_Import_1.ini failed"),
361 import_file_name));
363 else {
364 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s imported\n"), import_file_name));
366 // Imported clean; verify content. See ini file for expected content.
367 // Verify the expected sections are there, but no others. Verify the
368 // expected keys are there, but no others.
369 int section1_seen = 0, section2_seen = 0;
370 int somekey_seen = 0, someotherkey_seen = 0;
371 int index;
372 ACE_TString sect_name;
373 const ACE_Configuration_Section_Key &root = cf.root_section ();
374 for (index = 0;
375 (status = cf.enumerate_sections (root, index, sect_name)) == 0;
376 ++index) {
377 if (index > 1) // There are only two sections.
378 ACE_ERROR ((LM_ERROR,
379 ACE_TEXT ("Enumerated %d sections; expected 2\n"),
380 index + 1));
381 else {
382 ACE_DEBUG ((LM_DEBUG,
383 ACE_TEXT ("Enumerated to section %s\n"),
384 sect_name.c_str ()));
385 if (sect_name == ACE_TEXT ("SectionOne")) {
386 if (section1_seen)
387 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %s multiple times!\n"),
388 sect_name.c_str ()));
389 section1_seen = 1;
390 // Check for values in this section.
391 ACE_Configuration_Section_Key sect1;
392 if (cf.open_section (root, sect_name.c_str (), 0, sect1) != 0)
393 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to open section: %s\n"),
394 sect_name.c_str ()));
395 else {
396 int val_index = 0, val_status;
397 ACE_TString val_name, value;
398 ACE_Configuration::VALUETYPE val_type;
399 while ((val_status =
400 cf.enumerate_values
401 (sect1, val_index, val_name, val_type)) == 0) {
402 ACE_DEBUG ((LM_DEBUG,
403 ACE_TEXT ("Enumerated %s, type %d\n"),
404 val_name.c_str (),
405 val_type));
406 if (val_type != ACE_Configuration::STRING)
407 ACE_ERROR ((LM_ERROR,
408 ACE_TEXT ("Expected %s to be STRING, but %d\n"),
409 val_name.c_str (),
410 val_type));
411 if (val_name == ACE_TEXT ("SomeKey")) {
412 if (somekey_seen)
413 ACE_ERROR ((LM_ERROR,
414 ACE_TEXT ("Saw %s more than once\n"),
415 val_name.c_str ()));
416 somekey_seen = 1;
418 else
419 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unexpected key %s\n"),
420 val_name.c_str ()));
421 if ((val_status = cf.get_string_value
422 (sect1, val_name.c_str (), value)) != 0)
423 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Can't get value of %s\n"),
424 val_name.c_str ()));
425 else {
426 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s value: %s\n"),
427 val_name.c_str (), value.c_str ()));
428 if (value != ACE_TEXT ("SomeValue")) {
429 ACE_ERROR ((LM_ERROR,
430 ACE_TEXT ("SomeKey: %s; expected SomeValue\n")));
433 ++val_index;
435 if (val_status == 1) {
436 if (val_index != 1) // Should have only seen 1
437 ACE_ERROR ((LM_ERROR,
438 ACE_TEXT ("Expected 1 value; saw %d\n"),
439 index));
441 else
442 ACE_ERROR ((LM_ERROR,
443 ACE_TEXT ("Error enumerating %s; status %d\n"),
444 sect_name.c_str (), val_status));
447 else if (sect_name == ACE_TEXT ("SectionTwo")) {
448 if (section2_seen)
449 ACE_ERROR ((LM_ERROR,
450 ACE_TEXT ("Saw %s multiple times!\n"),
451 sect_name.c_str ()));
452 section2_seen = 1;
453 // Check for values in this section.
454 ACE_Configuration_Section_Key sect2;
455 if (cf.open_section (root, sect_name.c_str (), 0, sect2) != 0)
456 ACE_ERROR ((LM_ERROR,
457 ACE_TEXT ("Failed to open section: %s\n"),
458 sect_name.c_str ()));
459 else {
460 int val_index = 0, val_status;
461 ACE_TString val_name, value;
462 ACE_Configuration::VALUETYPE val_type;
463 while ((val_status = cf.enumerate_values
464 (sect2, val_index, val_name, val_type)) == 0) {
465 ACE_DEBUG ((LM_DEBUG,
466 ACE_TEXT ("Enumerated %s, type %d\n"),
467 val_name.c_str (),
468 val_type));
469 if (val_type != ACE_Configuration::STRING)
470 ACE_ERROR ((LM_ERROR,
471 ACE_TEXT ("Expected %s to be STRING, but %d\n"),
472 val_name.c_str (), val_type));
473 if (val_name == ACE_TEXT ("SomeOtherKey")) {
474 if (someotherkey_seen)
475 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %s more than once\n"),
476 val_name.c_str ()));
477 someotherkey_seen = 1;
479 else
480 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unexpected key %s\n"),
481 val_name.c_str ()));
482 if ((val_status = cf.get_string_value
483 (sect2, val_name.c_str (), value)) != 0)
484 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Can't get value of %s\n"),
485 val_name.c_str ()));
486 else {
487 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s value: %s\n"),
488 val_name.c_str (), value.c_str ()));
489 if (value != ACE_TEXT ("SomeOtherValue")) {
490 ACE_ERROR ((LM_ERROR,
491 ACE_TEXT ("SomeOtherKey: %s; expected SomeOtherValue\n")));
494 ++val_index;
496 if (val_status == 1) {
497 if (val_index != 1) // Should have only seen 1
498 ACE_ERROR ((LM_ERROR,
499 ACE_TEXT ("Expected 1 value; saw %d\n"),
500 index));
502 else
503 ACE_ERROR ((LM_ERROR,
504 ACE_TEXT ("Error enumerating %s; status %d\n"),
505 sect_name.c_str (), val_status));
508 else {
509 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw unexpected section: %s\n"),
510 sect_name.c_str ()));
514 if (status == 1) { // Ran out of sections
515 if (index != 2)
516 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Saw %d sections; expected 2\n"),
517 index));
519 else
520 ACE_ERROR ((LM_ERROR,
521 ACE_TEXT ("Error enumerating sections; status %d\n"),
522 status));
526 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
528 ACE_Configuration_Win32Registry RegConfig (HKEY_LOCAL_MACHINE);
529 int result = test_subkey_path (&RegConfig);
530 if (result)
531 ACE_ERROR_RETURN ((LM_ERROR,
532 ACE_TEXT ("Win32Registry test HKEY_LOCAL_MACHINE")
533 ACE_TEXT (" failed (%d)\n"), result),
534 -1);
536 // test win32 registry implementation.
537 HKEY root =
538 ACE_Configuration_Win32Registry::resolve_key (HKEY_LOCAL_MACHINE,
539 ACE_TEXT ("Software\\ACE\\test"));
540 if (!root)
541 ACE_ERROR_RETURN ((LM_ERROR,
542 ACE_TEXT ("resolve_key is broken\n")), -2);
544 // test resolving of forward slashes
545 HKEY root_fs =
546 ACE_Configuration_Win32Registry::resolve_key (HKEY_LOCAL_MACHINE,
547 ACE_TEXT ("Software/ACE/test"), 0);
548 if (!root_fs)
549 ACE_ERROR_RETURN ((LM_ERROR,
550 ACE_TEXT ("resolve_key resolving slashes is broken\n")),
551 -2);
553 ACE_Configuration_Win32Registry RegConfig (root);
555 int const result = test (&RegConfig);
556 if (result)
557 ACE_ERROR_RETURN ((LM_ERROR,
558 ACE_TEXT ("Win32 registry test root failed (%d)\n"),
559 result),
560 -1);
563 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
565 // Test Heap version
566 ACE_Configuration_Heap heap_config;
568 if (heap_config.open () != 0)
569 ACE_ERROR_RETURN ((LM_ERROR,
570 ACE_TEXT ("Cannot open %p\n"),
571 ACE_TEXT ("local-heap config")),
572 -1);
573 if (heap_config.open () == 0)
575 ACE_ERROR_RETURN ((LM_ERROR,
576 ACE_TEXT ("Re-open heap allowed; bugzilla 3724\n")),
577 -1);
579 else if (errno != EBUSY)
581 ACE_ERROR_RETURN ((LM_ERROR,
582 ACE_TEXT ("Re-open heap expected EBUSY (%d), ")
583 ACE_TEXT ("got %d: bugzilla 3724\n"),
584 EBUSY, ACE_ERRNO_GET),
585 -1);
588 int result = test_subkey_path (&heap_config);
589 if (result)
590 ACE_ERROR_RETURN ((LM_ERROR,
591 ACE_TEXT ("Heap Config subkey test failed (%d)\n"),
592 result),
593 -1);
597 int result = test (&heap_config);
598 if (result)
599 ACE_ERROR_RETURN ((LM_ERROR,
600 ACE_TEXT ("Heap Configuration test failed (%d)\n"),
601 result),
602 -1);
605 #if !defined (ACE_LACKS_MMAP)
606 // Test persistent heap version
607 ACE_OS::unlink (ACE_TEXT ("test.reg"));
608 ACE_Configuration_Heap pers_config;
610 if (pers_config.open (ACE_TEXT ("test.reg")))
611 ACE_ERROR_RETURN ((LM_ERROR,
612 ACE_TEXT ("Cannot open %p\n"),
613 ACE_TEXT ("test.reg")),
614 -1);
615 if (pers_config.open (ACE_TEXT ("test.reg")) == 0)
617 ACE_ERROR_RETURN ((LM_ERROR,
618 ACE_TEXT ("Re-open(mmap) allowed; bugzilla 3724\n")),
619 -1);
621 else if (errno != EBUSY)
623 ACE_ERROR_RETURN ((LM_ERROR,
624 ACE_TEXT ("Re-open(mmap) expected EBUSY (%d), ")
625 ACE_TEXT ("got %d: bugzilla 3724\n"),
626 EBUSY, ACE_ERRNO_GET),
627 -1);
629 if (pers_config.open () == 0)
631 ACE_ERROR_RETURN ((LM_ERROR,
632 ACE_TEXT ("Re-open(new) allowed; bugzilla 3724\n")),
633 -1);
635 else if (errno != EBUSY)
637 ACE_ERROR_RETURN ((LM_ERROR,
638 ACE_TEXT ("Re-open(new) expected EBUSY (%d), ")
639 ACE_TEXT ("got %d: bugzilla 3724\n"),
640 EBUSY, ACE_ERRNO_GET),
641 -1);
645 int result = test (&pers_config);
646 if (result)
647 ACE_ERROR_RETURN ((LM_ERROR,
648 ACE_TEXT ("Persistent Heap Config test failed (%d)\n"),
649 result),
650 -1);
652 #endif /* !ACE_LACKS_MMAP */
654 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Test passed\n")));
655 return 0;
658 static int
659 build_config_object (ACE_Configuration& cfg)
661 ACE_Configuration_Section_Key root = cfg.root_section ();
662 ACE_Configuration_Section_Key NetworkSection;
663 ACE_Configuration_Section_Key LoggerSection;
664 ACE_Configuration_Section_Key BinarySection;
666 if (cfg.open_section (root,
667 ACE_TEXT ("network"),
669 NetworkSection))
670 return -1;
672 if (cfg.set_integer_value (NetworkSection,
673 ACE_TEXT ("TimeToLive"),
674 100))
675 return -2;
676 else if (cfg.set_string_value (NetworkSection,
677 ACE_TEXT ("Delay"),
678 ACE_TString (ACE_TEXT ("FALSE"))))
679 return -3;
680 else if (cfg.set_string_value (NetworkSection,
681 ACE_TEXT ("DestIPAddress"),
682 ACE_TString (ACE_TEXT ("localhost"))))
683 return -4;
684 else if (cfg.set_integer_value (NetworkSection,
685 ACE_TEXT ("DestPort"),
686 12670))
687 return -5;
688 else if (cfg.set_integer_value (NetworkSection,
689 ACE_TEXT ("ReconnectInterval"),
691 return -6;
693 if (cfg.open_section (root,
694 ACE_TEXT ("logger"),
696 LoggerSection))
697 return -7;
699 if (cfg.set_string_value (LoggerSection,
700 ACE_TEXT ("Heading"),
701 ACE_TString (ACE_TEXT ("ACE - Adaptive Communication Environment"))))
702 return -8;
703 else if (cfg.set_integer_value (LoggerSection,
704 ACE_TEXT ("SeekIndex"),
705 14))
706 return -9;
707 else if (cfg.set_integer_value (LoggerSection,
708 ACE_TEXT ("TraceLevel"),
710 return -10;
711 else if (cfg.set_string_value (LoggerSection,
712 ACE_TEXT ("Justification"),
713 ACE_TString (ACE_TEXT ("left_justified"))))
714 return -11;
715 else if (cfg.set_string_value (LoggerSection,
716 ACE_TEXT ("LogFilePath"),
717 ACE_TString (ACE_TEXT ("log/"))))
718 return -12;
719 else if (cfg.set_string_value (LoggerSection,
720 ACE_TEXT ("TransactionFilePath"),
721 ACE_TString (ACE_TEXT ("data/"))))
722 return -13;
724 if (cfg.open_section (root,
725 ACE_TEXT ("binary"),
727 BinarySection))
728 return -14;
730 u_char data[80];
732 for (int i = 0; i < 80; i++)
733 data[i] = i + 128;
735 if (cfg.set_binary_value (BinarySection,
736 ACE_TEXT ("data"),
737 data,
738 80))
739 return -15;
741 ACE_TString string((ACE_TCHAR*) 0);// = '0';
742 // Try to set the unnamed, default value.
743 if (cfg.set_string_value (LoggerSection,
744 0,//string.c_str (),//0, //ACE_TEXT ("x"),
745 ACE_TString (ACE_TEXT ("some string"))))
746 ACE_ERROR_RETURN ((LM_ERROR,
747 ACE_TEXT ("could not set value with null name\n")),
748 -16);
750 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("here\n")));
751 //return 0;
752 //ACE_TString string;
753 ACE_TString name ((ACE_TCHAR*)0);
754 if (cfg.get_string_value (LoggerSection,
755 name.c_str (), //0, //ACE_TEXT ("x"),
756 string))
757 ACE_ERROR_RETURN ((LM_ERROR,
758 ACE_TEXT ("error using ACE_TString::c_str() == %d, len == %d\n"),
759 name.c_str(), name.length ()),
760 -17);
762 ACE_DEBUG ((LM_DEBUG,
763 ACE_TEXT ("the value for the unnamed var=(%s)\n"),
764 string.c_str ()));
766 return 0;
770 * Test ACE_Configuration::operator==
773 Config_Test::testEquality ()
775 // create and open 2 ACE_Configuration objects.
776 ACE_Configuration_Heap heap1;
777 ACE_Configuration_Heap heap2;
778 if ((heap1.open ()) != 0)
780 ACE_ERROR_RETURN ((LM_ERROR,
781 ACE_TEXT ("Cannot open heap1\n")),
782 -1);
784 else if ((heap2.open ()) != 0)
786 ACE_ERROR_RETURN ((LM_ERROR,
787 ACE_TEXT ("Cannot open heap2\n")),
788 -1);
791 // populate them equally
792 if (build_config_object (heap1) != 0 ||
793 build_config_object (heap2) != 0)
794 ACE_ERROR_RETURN ((LM_ERROR,
795 ACE_TEXT ("could not build config object\n")),
796 -1);
798 // test equality
799 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should equal...\n")));
800 if (heap1 == heap2)
802 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do ;-)\n")));
804 else
806 ACE_ERROR_RETURN ((LM_ERROR,
807 ACE_TEXT ("And they do not :-(\n")
808 ACE_TEXT ("operator== Failed when objects equal\n")),
809 -1);
812 // add a section and value to heap1
813 ACE_Configuration_Section_Key root1 = heap1.root_section ();
814 ACE_Configuration_Section_Key NewSection;
815 if (heap1.open_section (root1,
816 ACE_TEXT ("NewSection"),
818 NewSection))
819 ACE_ERROR_RETURN ((LM_ERROR,
820 ACE_TEXT ("Error adding section to heap1\n")),
821 -1);
822 else if (heap1.set_integer_value (NewSection,
823 ACE_TEXT ("TestIntValue"),
824 100))
825 ACE_ERROR_RETURN ((LM_ERROR,
826 ACE_TEXT ("Error adding value to heap1\n")),
827 -2);
829 // test equality
830 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
831 if (heap1 == heap2)
832 ACE_ERROR_RETURN ((LM_ERROR,
833 ACE_TEXT ("They Do :-(\noperator== Failed ")
834 ACE_TEXT ("when lhs contains data not in rhs\n")),
835 -1);
836 else
837 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not ;-)\n")));
840 // add same section to heap2
842 ACE_Configuration_Section_Key root2 = heap2.root_section ();
843 ACE_Configuration_Section_Key NewSection2;
844 if (heap2.open_section (root2,
845 ACE_TEXT ("NewSection"),
847 NewSection2))
848 ACE_ERROR_RETURN ((LM_ERROR,
849 ACE_TEXT ("Error adding section to heap2\n")),
850 -1);
851 else if (heap2.set_integer_value (NewSection2,
852 ACE_TEXT ("TestIntValue"),
853 100))
854 ACE_ERROR_RETURN ((LM_ERROR,
855 ACE_TEXT ("Error adding value to heap2\n")),
856 -2);
857 else if (heap2.set_integer_value (NewSection2,
858 ACE_TEXT ("TestIntValue2"),
859 100))
860 ACE_ERROR_RETURN ((LM_ERROR,
861 ACE_TEXT ("Error adding second value to heap2\n")),
862 -2);
864 // test equality
865 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
866 if (heap1 == heap2)
867 ACE_ERROR_RETURN ((LM_ERROR,
868 ACE_TEXT ("And They Do :-(\noperator== Failed ")
869 ACE_TEXT ("when rhs contains value not in lhs\n")),
870 -1);
871 else
872 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not ;-)\n")));
874 // add new value in heap 1
875 if (heap1.set_integer_value (NewSection,
876 ACE_TEXT ("TestIntValue2"),
877 100))
878 ACE_ERROR_RETURN ((LM_ERROR,
879 ACE_TEXT ("Error adding second value to heap1\n")),
880 -2);
882 // test equality
883 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should be equal...\n")));
884 if (heap1 == heap2)
885 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they are ;-)\n")));
886 else
887 ACE_ERROR_RETURN ((LM_ERROR,
888 ACE_TEXT ("And they are not :-(\n")
889 ACE_TEXT ("operator== Failed\n")),
890 -1);
892 // Add a new section to heap2
893 ACE_Configuration_Section_Key AnotherNewSection2;
894 if (heap2.open_section (root2,
895 ACE_TEXT ("AnotherNewSection"),
897 AnotherNewSection2))
898 ACE_ERROR_RETURN ((LM_ERROR,
899 ACE_TEXT ("Error adding second section to heap2\n")),
900 -1);
901 else if (heap2.set_integer_value (AnotherNewSection2,
902 ACE_TEXT ("TestIntValue"),
903 100))
904 ACE_ERROR_RETURN ((LM_ERROR,
905 ACE_TEXT ("Error adding value in second section")
906 ACE_TEXT (" to heap2\n")),
907 -2);
909 // test equality
910 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should NOT equal...\n")));
911 if (heap1 == heap2)
912 ACE_ERROR_RETURN ((LM_ERROR,
913 ACE_TEXT ("And they do :-(\noperator== Failed ")
914 ACE_TEXT ("when rhs contains data not in lhs\n")),
915 -1);
916 else
917 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they do not :-)\n")));
919 // add section back to heap1
920 ACE_Configuration_Section_Key AnotherNewSection1;
921 if (heap1.open_section (root1,
922 ACE_TEXT ("AnotherNewSection"),
924 AnotherNewSection1))
925 ACE_ERROR_RETURN ((LM_ERROR,
926 ACE_TEXT ("Error adding second section to heap1\n")),
927 -1);
928 else if (heap1.set_integer_value (AnotherNewSection1,
929 ACE_TEXT ("TestIntValue"),
930 100))
931 ACE_ERROR_RETURN ((LM_ERROR,
932 ACE_TEXT ("Error adding second value to second ")
933 ACE_TEXT ("section in heap1\n")),
934 -2);
936 // test equality
937 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("The objects should be equal...\n")));
938 if (heap1 == heap2)
939 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("And they are ;-)\n")));
940 else
941 ACE_ERROR_RETURN ((LM_ERROR,
942 ACE_TEXT ("And they are not :-(\n")
943 ACE_TEXT ("operator== Failed\n")),
944 -1);
946 this->equality_tested_ = 1;
947 return 0;
951 * Compare INI import data in fromFile to origional data exported (in origional)
953 * This compare is destructive to the origional object.
954 * I realize that normally you would not do such an obscene thing but
955 * this funciton has a special purpose and I know my origional is not needed
956 * after calling this routine.
957 * This is done because configuration objects that are imported using the INI
958 * import store all data as strings. My origional has type information and I need to
959 * know if the import worked.
961 static int
962 iniCompare (ACE_Configuration_Heap& fromFile, ACE_Configuration_Heap& original)
964 bool rc = true; // start by guessing they are equal
966 int sectionIndex = 0;
967 ACE_TString sectionName;
969 const ACE_Configuration_Section_Key& fromFileRoot = fromFile.root_section ();
970 const ACE_Configuration_Section_Key& originalRoot = original.root_section ();
971 ACE_Configuration_Section_Key originalSection;
972 ACE_Configuration_Section_Key fromFileSection;
974 // loop through each section in the fromFile object
975 while ((rc) &&
976 (!fromFile.enumerate_sections (fromFileRoot,
977 sectionIndex,
978 sectionName)) )
980 // find that section in the original object
981 if (original.open_section (originalRoot,
982 sectionName.c_str (),
984 originalSection) != 0)
985 // If the original object does not contain the section then we
986 // are not equal.
987 rc = false;
988 else if (fromFile.open_section (fromFileRoot,
989 sectionName.c_str (),
991 fromFileSection) != 0)
992 // if there is some error opening the section in the fromFile
993 rc = false;
994 else
996 // Well the sections match
997 int valueIndex = 0;
998 ACE_TString valueName;
999 ACE_Configuration::VALUETYPE valueType;
1000 ACE_Configuration::VALUETYPE originalType;
1002 // Enumerate each value in the fromFile section
1003 while ((rc) &&
1004 (!fromFile.enumerate_values (fromFileSection,
1005 valueIndex,
1006 valueName,
1007 valueType)))
1009 // look for the same value in the original section
1010 if (original.find_value (originalSection,
1011 valueName.c_str (),
1012 originalType) != 0)
1013 // We're not equal if the same value cannot be found
1014 // in the original object.
1015 rc = false;
1016 else
1018 ACE_TString fromFileString, originalString;
1021 if (fromFile.get_string_value (fromFileSection,
1022 valueName.c_str (),
1023 fromFileString) != 0)
1024 // we're not equal if we cannot get this string
1025 rc = false;
1026 else if (originalType != ACE_Configuration::STRING) // If the original type is not a string
1028 // convert original data to a string.
1030 if (originalType == ACE_Configuration::INTEGER)
1032 u_int intValue;
1033 ACE_TCHAR int_value[32];
1035 if (original.get_integer_value (originalSection,
1036 valueName.c_str (),
1037 intValue) != 0)
1038 // we're not equal if we cannot get rhs int
1039 rc = false;
1041 ACE_OS::snprintf (int_value, 32, ACE_TEXT ("%08x"),
1042 intValue);
1043 originalString = int_value;
1045 else if (originalType == ACE_Configuration::BINARY)
1047 void* binary_data;
1048 size_t binary_length;
1050 if (original.get_binary_value (originalSection,
1051 valueName.c_str (),
1052 binary_data,
1053 binary_length))
1054 // we're not equal if we cannot get this string
1055 rc = false;
1056 else
1058 ACE_TCHAR bin_value[3];
1060 unsigned char* ptr = (unsigned char*)binary_data;
1061 while (binary_length)
1063 if (ptr != binary_data)
1064 originalString += ACE_TEXT (",");
1066 ACE_OS::snprintf (bin_value, 3,
1067 ACE_TEXT ("%02x"),
1068 *ptr);
1069 originalString += bin_value;
1070 --binary_length;
1071 ++ptr;
1073 delete [] (char *)binary_data;
1074 }// end successful binary read
1075 }// end if originalType was binary
1076 else
1077 // if the type is invalid, then go ahead and fail it.
1078 rc = false;
1079 }// end if the original type was not a string.
1080 else
1082 if (original.get_string_value (originalSection,
1083 valueName.c_str (),
1084 originalString) != 0)
1086 // we're not equal if we cannot get rhs string
1087 rc = false;
1092 rc &= fromFileString == originalString;
1094 if (rc)
1095 // before we move on remove this value from the original.
1096 original.remove_value (originalSection,
1097 valueName.c_str ());
1098 }// end else if values match.
1100 valueIndex++;
1101 }// end value while loop
1103 // at this point the original should have no values. look
1104 // for values in the original section
1105 valueIndex = 0;
1106 while ((rc) &&
1107 (!original.enumerate_values (originalSection,
1108 valueIndex,
1109 valueName,
1110 originalType)))
1111 valueIndex++;
1113 // having a value indicates a mismatch
1114 rc = valueIndex == 0;
1115 }// end else if sections match.
1117 if (rc)
1118 // before we move on remove the section from the original.
1119 original.remove_section (originalRoot,
1120 sectionName.c_str (),
1121 0); // do not remove subsections.
1123 ++sectionIndex;
1124 }// end section while loop
1126 // Finally, if the original has any sections, then we're not equal
1127 sectionIndex = 0;
1128 while ((rc) &&
1129 (!original.enumerate_sections (originalRoot,
1130 sectionIndex,
1131 sectionName)))
1132 ++sectionIndex;
1134 rc = sectionIndex == 0;
1136 return rc;
1139 // change a network section value
1140 int Config_Test::change_one (ACE_Configuration &cfg, u_int a)
1142 ACE_Configuration_Section_Key root = cfg.root_section ();
1143 ACE_Configuration_Section_Key NetworkSection;
1144 ACE_Configuration_Section_Key LoggerSection;
1145 ACE_Configuration_Section_Key BinarySection;
1147 if (cfg.open_section (root,
1148 ACE_TEXT ("network"),
1150 NetworkSection))
1151 return -1;
1153 if (cfg.set_integer_value (NetworkSection,
1154 ACE_TEXT ("TimeToLive"),
1156 return -2;
1158 return 0;
1161 // Used to test INI Import Export class
1164 Config_Test::testIniFormat ()
1166 int rc = 0;
1167 if (!this->equality_tested_)
1169 rc = this->testEquality ();
1170 if (rc != 0)
1172 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Equality Test Failed\n")));
1173 return rc;
1177 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing INI Format Import/Export\n")));
1178 ACE_Configuration_Heap fromFile;
1180 // 1. Creates an ACE_Configuration_Heap object
1181 ACE_Configuration_Heap original;
1183 rc = original.open ();
1184 if (rc == 0)
1186 rc = build_config_object (original);
1187 // 2. Calls build_config_object to populate
1188 if (rc != 0)
1189 ACE_ERROR_RETURN ((LM_ERROR,
1190 ACE_TEXT ("Error populating original config ")
1191 ACE_TEXT ("object (%d)\n"),
1192 rc),
1193 -1);
1194 // 3. Export
1195 ACE_Ini_ImpExp importExport (original);
1197 rc = importExport.export_config (ACE_TEXT ("testConfig.ini"));
1198 if (rc != 0)
1199 ACE_ERROR_RETURN ((LM_ERROR,
1200 ACE_TEXT ("Error Exporting (%d)\n"),
1201 rc),
1202 -1);
1204 else
1205 ACE_ERROR_RETURN ((LM_ERROR,
1206 ACE_TEXT ("Could not open original object (%d)\n"),
1207 rc),
1208 -1);
1210 // At this point we've successfully created, populated and written
1211 // the configuration object
1212 // 5. Creates a new ACE_Configuration_Heap object
1213 rc = fromFile.open ();
1214 if (rc == 0)
1216 // 6. Imports
1217 ACE_Ini_ImpExp importExport (fromFile);
1219 rc = importExport.import_config (ACE_TEXT ("testConfig.ini"));
1220 if (rc != 0)
1221 ACE_ERROR_RETURN ((LM_ERROR,
1222 ACE_TEXT ("Error Exporting (%d)\n"),
1223 rc),
1224 -1);
1226 // 7. Compares to original.
1227 // This is a special compare since files imported using the
1228 // INI file import do not contain type information
1230 // NOTE: After this call the original object will be invalid!!!
1232 if (!iniCompare (fromFile, original))
1233 ACE_ERROR_RETURN ((LM_ERROR,
1234 ACE_TEXT ("Object read from file does not ")
1235 ACE_TEXT ("equal original (%d)\n"),
1236 rc),
1237 -1);
1238 }// end if heap could not be opened.
1239 else
1240 ACE_ERROR_RETURN ((LM_ERROR,
1241 ACE_TEXT ("Could not open fromFile object (%d)\n"),
1242 rc),
1243 -1);
1245 // 8. Calls old "read_config" methods on the new object
1247 int nTimeToLive;
1248 int bDelay;
1249 int nDestPort;
1250 int nReconnectInterval;
1251 int nTraceLevel;
1253 ACE_TCHAR pszDestIPAddress[TEST_MAX_STRING];
1254 ACE_TCHAR pszLogFilePath[TEST_MAX_STRING];
1255 ACE_TCHAR pszTransactionFilePath[TEST_MAX_STRING];
1256 ACE_TCHAR pszHeading[TEST_MAX_STRING];
1257 ACE_TCHAR pszJustification[TEST_MAX_STRING];
1259 ACE_Configuration_Section_Key root = fromFile.root_section ();
1261 // Process [network] section
1262 ACE_Configuration_Section_Key NetworkSection;
1263 if (fromFile.open_section (root,
1264 ACE_TEXT ("network"),
1266 NetworkSection) == 0)
1268 this->get_section_integer (fromFile,
1269 NetworkSection,
1270 ACE_TEXT ("TimeToLive"),
1271 &nTimeToLive,
1273 20);
1275 this->get_section_boolean (fromFile,
1276 NetworkSection,
1277 ACE_TEXT ("Delay"),
1278 &bDelay);
1280 this->get_section_string (fromFile,
1281 NetworkSection,
1282 ACE_TEXT ("DestIPAddress"),
1283 pszDestIPAddress,
1284 TEST_MAX_STRING);
1286 this->get_section_integer (fromFile,
1287 NetworkSection,
1288 ACE_TEXT ("DestPort"),
1289 &nDestPort,
1291 65535);
1293 this->get_section_integer (fromFile,
1294 NetworkSection,
1295 ACE_TEXT ("ReconnectInterval"),
1296 &nReconnectInterval,
1298 65535);
1299 }// end of "network" section
1301 // Process [logger] section
1302 ACE_Configuration_Section_Key LoggerSection;
1303 if (fromFile.open_section (root,
1304 ACE_TEXT ("logger"),
1306 LoggerSection) == 0)
1308 this->get_section_string (fromFile,
1309 LoggerSection,
1310 ACE_TEXT ("Heading"),
1311 pszHeading,
1312 TEST_MAX_STRING);
1313 this->get_section_integer (fromFile,
1314 LoggerSection,
1315 ACE_TEXT ("TraceLevel"),
1316 &nTraceLevel,
1318 20);
1319 this->get_section_string (fromFile,
1320 LoggerSection,
1321 ACE_TEXT ("Justification"),
1322 pszJustification,
1323 TEST_MAX_STRING);
1324 this->get_section_string (fromFile,
1325 LoggerSection,
1326 ACE_TEXT ("LogFilePath"),
1327 pszLogFilePath,
1328 TEST_MAX_STRING);
1329 this->get_section_string (fromFile,
1330 LoggerSection,
1331 ACE_TEXT ("TransactionFilePath"),
1332 pszTransactionFilePath,
1333 TEST_MAX_STRING);
1334 }// end of "logger" section
1336 if (!rc)
1337 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("INI Format Import/Export Works ;-)\n")));
1338 return rc;
1341 // Used to test registry Import Export class
1344 Config_Test::testRegFormat ()
1346 int rc = 0;
1347 if (!this->equality_tested_)
1349 rc = this->testEquality ();
1350 if (rc != 0)
1352 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Equality Test Failed\n")));
1353 return rc;
1357 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing Registry Format Import/Export\n")));
1358 ACE_Configuration_Heap fromFile;
1360 // 1. Creates an ACE_Configuration_Heap object
1361 ACE_Configuration_Heap original;
1363 rc = original.open ();
1364 if (rc == 0)
1366 // 2. Calls build_config_object to populate
1367 rc = build_config_object (original);
1368 if (rc != 0)
1369 ACE_ERROR_RETURN ((LM_ERROR,
1370 ACE_TEXT ("Error populating original config ")
1371 ACE_TEXT ("object (%d)\n"),
1372 rc),
1373 -1);
1374 // 3. Export
1375 ACE_Registry_ImpExp importExport (original);
1377 rc = importExport.export_config (ACE_TEXT ("testConfig.ini"));
1378 if (rc != 0)
1379 ACE_ERROR_RETURN ((LM_ERROR,
1380 ACE_TEXT ("Error Exporting (%d)\n"),
1381 rc),
1382 -1);
1384 else
1385 ACE_ERROR_RETURN ((LM_ERROR,
1386 ACE_TEXT ("Could not open original object (%d)\n"),
1387 rc),
1388 -1);
1390 // At this point we've successfully created, populated and written
1391 // the configuration object
1392 // 5. Creates a new ACE_Configuration_Heap object
1393 rc = fromFile.open ();
1394 if (rc == 0)
1396 // 6. Imports
1397 ACE_Registry_ImpExp importExport (fromFile);
1399 rc = importExport.import_config (ACE_TEXT ("testConfig.ini"));
1400 if (rc != 0)
1401 ACE_ERROR_RETURN ((LM_ERROR,
1402 ACE_TEXT("Error Exporting (%d)\n"),
1403 rc),
1404 -1);
1406 // 7. Compares to original.
1407 if (fromFile != original)
1408 ACE_ERROR_RETURN ((LM_ERROR,
1409 ACE_TEXT ("Object read from file does not ")
1410 ACE_TEXT ("equal original (%d)\n"),
1411 rc),
1412 -1);
1414 // 7.1 Change a value and test NOT equal case
1415 change_one (original, 101);
1416 if (fromFile == original)
1418 ACE_ERROR_RETURN ((LM_ERROR,
1419 ACE_TEXT ("not pass value change test (%d)\n"),
1420 rc),
1421 -1);
1424 // 7.2 change value back, they should be equal now
1425 change_one (original, 100);
1426 if (fromFile != original)
1428 ACE_ERROR_RETURN ((LM_ERROR,
1429 ACE_TEXT ("not pass value change test (%d)\n"),
1430 rc),
1431 -1);
1434 }// end if heap could not be opened.
1435 else
1436 ACE_ERROR_RETURN ((LM_ERROR,
1437 ACE_TEXT ("Could not open fromFile object (%d)\n"),
1438 rc),
1439 -1);
1441 if (!rc)
1442 ACE_DEBUG ((LM_DEBUG,
1443 ACE_TEXT ("Registry Format Import/Export Works ;-)\n")));
1444 return rc;
1448 // Reads a string value from a configuration object.
1450 void
1451 Config_Test::get_section_string (ACE_Configuration& config,
1452 ACE_Configuration_Section_Key& SectionKey,
1453 const ACE_TCHAR* pszName,
1454 ACE_TCHAR* pszVariable,
1455 int nMaxLength)
1457 ACE_TString StringValue;
1459 if (config.get_string_value (SectionKey,
1460 pszName,
1461 StringValue) == 0)
1463 ACE_OS::strncpy (pszVariable,
1464 StringValue.c_str (),
1465 nMaxLength);
1466 ACE_DEBUG ((LM_DEBUG,
1467 ACE_TEXT ("%s = %s\n"),
1468 pszName,
1469 pszVariable));
1473 // Reads an integer value from a configuration object (when it's
1474 // stored as a string)
1475 void
1476 Config_Test::get_section_integer (ACE_Configuration& config,
1477 ACE_Configuration_Section_Key& SectionKey,
1478 const ACE_TCHAR* pszName,
1479 int* nVariable,
1480 int nMinValue,
1481 int nMaxValue)
1483 ACE_TString StringValue;
1484 ACE_TCHAR pszString[30];
1485 ACE_OS::strcpy (pszString, ACE_TEXT ("0"));
1486 int IntegerValue = 0;
1488 if (config.get_string_value (SectionKey,
1489 pszName,
1490 StringValue) == 0)
1492 ACE_OS::strncpy (pszString,
1493 StringValue.c_str (),
1494 30);
1495 ACE_DEBUG ((LM_DEBUG,
1496 ACE_TEXT ("%s = %s\n"),
1497 pszName,
1498 pszString));
1501 // convert to integer
1502 IntegerValue = ACE_OS::atoi (pszString);
1503 IntegerValue = (IntegerValue < nMinValue) ? nMinValue : IntegerValue;
1504 IntegerValue = (IntegerValue > nMaxValue) ? nMaxValue : IntegerValue;
1505 *nVariable = IntegerValue;
1508 // Reads a boolean value from a configuration object (when it's stored as a string).
1510 void
1511 Config_Test::get_section_boolean (ACE_Configuration& config,
1512 ACE_Configuration_Section_Key& SectionKey,
1513 const ACE_TCHAR* pszName,
1514 int* pVariable)
1516 ACE_TString StringValue;
1517 ACE_TCHAR pszString[10];
1518 ACE_OS::strcpy (pszString, ACE_TEXT ("0"));
1520 if (config.get_string_value (SectionKey,
1521 pszName,
1522 StringValue) == 0)
1524 ACE_OS::strncpy (pszString,
1525 StringValue.c_str (),
1526 10);
1527 for (ACE_TCHAR* pSrc = pszString;
1528 *pSrc != ACE_TEXT ('\0');
1529 pSrc++)
1530 // Convert to uppercase
1531 if (ACE_OS::ace_islower (*pSrc))
1532 *pSrc = ACE_OS::ace_tolower (*pSrc);
1534 ACE_DEBUG ((LM_DEBUG,
1535 ACE_TEXT ("%s = %s\n"),
1536 pszName,
1537 pszString));
1539 if (ACE_OS::strcmp (pszString,
1540 ACE_TEXT ("TRUE")) == 0)
1541 *pVariable = 1;
1542 else if (ACE_OS::strcmp (pszString,
1543 ACE_TEXT ("FALSE")) == 0)
1544 *pVariable = 0;
1549 run_main (int, ACE_TCHAR *[])
1551 ACE_START_TEST (ACE_TEXT ("Config_Test"));
1552 int errors = 0;
1553 Config_Test manager;
1555 if ((errors += manager.testEquality ()) != 0)
1556 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the equality Test\n")));
1558 if ((errors += manager.testRegFormat ()) != 0)
1559 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the REG Format Test\n")));
1561 if ((errors += manager.testIniFormat ()) != 0)
1562 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed the INI Format Test\n")));
1564 if ((errors += run_tests ()) != 0)
1565 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Failed in run_tests\n")));
1567 ACE_END_TEST;
1568 return errors == 0 ? 0 : 1;