t_registry_configurator.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_registry_configurator                                        *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *******************************************************************************
00007 * Copyright (c) 1998-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 \*****************************************************************************/
00014 
00015 const int test_iterations = 10;
00016 
00017 //#define DEBUG_REGISTRY_CONFIGURATOR_TEST
00018   // uncomment for debugging version.
00019 
00020 #include <basis/function.h>
00021 #include <basis/guards.h>
00022 #include <basis/istring.h>
00023 #include <geometric/rectangle.cpp>
00024 #include <geometric/screen_rectangle.h>
00025 #include <mathematics/float_plus.h>
00026 #include <loggers/console_logger.h>
00027 #include <opsystem/registry_config.h>
00028 #include <opsystem/path_configuration.h>
00029 #include <data_struct/static_memory_gremlin.h>
00030 #include <textual/byte_format.h>
00031 
00032 #include <stdio.h>
00033 
00034 HOOPLE_STARTUP_CODE;
00035 
00036 using namespace geometric;
00037 
00038 typedef float_plus<double> frunkle;
00039 
00040 #define WHERE __WHERE__.s()
00041 
00042 const registry_configurator::registry_hives THE_HIVE
00043     = registry_configurator::hkey_current_user;
00044 
00045 const istring REGISTRY_SECTION = "boobo/tahini/nunkshus";
00046 
00047 int main(int formal(argc), char *formal(argv)[])
00048 {
00049 #ifdef __WIN32__
00050   // this test is only needed for win32 OSes.
00051   registry_configurator ini(THE_HIVE, registry_configurator::AUTO_STORE);
00052 
00053 console_logger out;
00054 
00055   for (int i = 0; i < test_iterations; i++) {  // outer loop bracket.
00056     // beginning of test sets.
00057 
00058     {
00059       const char *TEST_NAME = "zeroth test: cleaning section";
00060       ini.delete_section(REGISTRY_SECTION);
00061       if (ini.section_exists(REGISTRY_SECTION))
00062         deadly_error(REGISTRY_SECTION, TEST_NAME,
00063             "section still exists after deleting!");
00064     }
00065 
00066     {
00067       // first test set.
00068       const char *TEST_NAME = "first test: rectangle";
00069       // this tests whether rectangle storage works.
00070       screen_rectangle default_rectangle(10, 289, 388, 191);
00071       ini.delete_entry(REGISTRY_SECTION, "window_size");
00072       screen_rectangle win_size;
00073       istring tmp = ini.load(REGISTRY_SECTION, "window_size",
00074           default_rectangle.text_form());
00075       win_size.from_text(tmp);
00076       if (win_size != default_rectangle)
00077         deadly_error(REGISTRY_SECTION, TEST_NAME,
00078             "rectangle not equal to default");
00079       screen_rectangle new_size(23, 49, 129, 93);
00080       ini.store(REGISTRY_SECTION, "window_size", new_size.text_form());
00081       screen_rectangle current_size;
00082       tmp = ini.load(REGISTRY_SECTION, "window_size",
00083           default_rectangle.text_form());
00084       current_size.from_text(tmp);
00085       if (current_size != new_size)
00086         deadly_error(REGISTRY_SECTION, TEST_NAME,
00087               "rectangle not equal to second size stored");
00088     }
00089     {
00090       // second test set.
00091       const char *TEST_NAME = "second test: string";
00092       istring junk("this is a junky string to be stored as bytes....");
00093       byte_array to_store(junk.length() + 1, (byte *)junk.observe());
00094       istring as_bytes;
00095       byte_format::bytes_to_string(to_store, as_bytes);
00096       ini.store(REGISTRY_SECTION + "/test_of_byte_store", "test1", as_bytes);
00097       istring blort = "blort_fest!";
00098       istring rettle = ini.load(REGISTRY_SECTION + "/test_of_byte_store",
00099           "test1", blort);
00100       byte_array found_byte;
00101       byte_format::string_to_bytes(rettle, found_byte);
00102       istring found_junk((const char *)found_byte.observe());
00103       if (rettle == blort)
00104         deadly_error(REGISTRY_SECTION, TEST_NAME,
00105            "registry_configurator load failed: default was used");
00106       else if (found_junk != junk)
00107         deadly_error(REGISTRY_SECTION, TEST_NAME,
00108            "registry_configurator load failed: result differed from original");
00109     }
00110     {
00111       // third test set.
00112       const char *TEST_NAME = "third test: frunkle";
00113       frunkle def_frunkle(3.14159265358);
00114       istring def_text(istring::SPRINTF, "%f", def_frunkle.value());
00115       ini.store(REGISTRY_SECTION, TEST_NAME, def_text);
00116       istring found_string = ini.load(REGISTRY_SECTION, TEST_NAME, "9949494.3");
00117       frunkle found_frunkle = found_string.convert(0.0);
00118       if (found_frunkle == frunkle(9949494.3))
00119         deadly_error(REGISTRY_SECTION, TEST_NAME, 
00120            "registry_configurator load failed: default was used");
00121       if (found_frunkle != def_frunkle)
00122         deadly_error(REGISTRY_SECTION, TEST_NAME, 
00123            "registry_configurator load failed: saved value differed");
00124     }
00125     {
00126       // fourth test set.
00127       const char *TEST_NAME = "fourth test: frunkle";
00128       frunkle def_frunkle(1487335673.1415926535834985987);
00129       istring def_text(istring::SPRINTF, "%f", def_frunkle.value());
00130       ini.store(REGISTRY_SECTION + "/test", "frunkle_test", def_text);
00131       istring found_string = ini.load(REGISTRY_SECTION + "/test",
00132           "frunkle_test", "9949494.3");
00133       frunkle found_frunkle = found_string.convert(0.0);
00134       if (found_frunkle == frunkle(9949494.3))
00135         deadly_error(REGISTRY_SECTION, TEST_NAME,
00136            "registry_configurator load failed: wrong default was used");
00137       if (found_frunkle != def_frunkle)
00138         deadly_error(REGISTRY_SECTION, TEST_NAME, 
00139            "registry_configurator load failed: saved value differed");
00140     }
00141     {
00142       // fifth test set.
00143       const char *TEST_NAME = "fifth test: bytes";
00144       istring urp("urp");
00145       istring junk("this is a junky string to be stored as bytes....");
00146       byte_array default_bytes(urp.length() + 1, (byte *)urp.observe());
00147       istring defbytes_string;
00148       byte_format::bytes_to_string(default_bytes, defbytes_string);
00149       byte_array found;
00150       istring tmp = ini.load(REGISTRY_SECTION + "/test_of_byte_store", "test1", defbytes_string);
00151       byte_format::string_to_bytes(tmp, found);
00152       istring string_found = (char *)found.observe();
00153       if (string_found == urp)
00154         deadly_error(REGISTRY_SECTION, TEST_NAME,
00155             "registry_configurator load_bytes failed: default was used");
00156       if (string_found.length() != junk.length())
00157         deadly_error(REGISTRY_SECTION, TEST_NAME,
00158             "registry_configurator load_bytes failed: array lengths differ");
00159       if (string_found != junk)
00160         deadly_error(REGISTRY_SECTION, TEST_NAME,
00161             "registry_configurator load_bytes failed: arrays differ");
00162     }
00163     {
00164       // sixth test set.
00165       const char *TEST_NAME = "sixth test: blank string";
00166       ini.delete_entry(REGISTRY_SECTION + "/test_of_blank_string", "test1");
00167       istring blank("");
00168       istring fund = ini.load(REGISTRY_SECTION + "/test_of_blank_string", "test1", blank);
00169       if (fund != blank)
00170         deadly_error(REGISTRY_SECTION, TEST_NAME, "registry_configurator load string "
00171                "with blank default failed: didn't return blank");
00172       ini.delete_entry(REGISTRY_SECTION + "/test_of_blank_string", "test1");
00173       istring non_blank("blinkblankblunk");
00174       fund = ini.load(REGISTRY_SECTION + "/test_of_blank_string", "test1", non_blank);
00175       if (fund != non_blank)
00176         deadly_error(REGISTRY_SECTION, TEST_NAME, "registry_configurator load string "
00177                "with non-blank default failed: didn't return default");
00178       fund = ini.load(REGISTRY_SECTION + "/test_of_blank_string", "test1", blank);
00179       if (fund != non_blank)
00180         deadly_error(REGISTRY_SECTION, TEST_NAME, "registry_configurator load string "
00181                "with blank default failed: returned wrong string");
00182     }
00183   }
00184 
00185   // clean up after the test.
00186   ini.delete_section(REGISTRY_SECTION);
00187 
00188 #endif // win32.
00189 
00190   istring to_print("registry_configurator:: works for those functions tested.");
00191   guards::alert_message(to_print.s());
00192   return 0;
00193 }
00194 

Generated on Fri Nov 28 04:29:39 2008 for HOOPLE Libraries by  doxygen 1.5.1