cached_value_tests.cpp
Go to the documentation of this file.00001
00011 #include <cstdlib>
00012 #include <iostream>
00013 #include <string>
00014
00015 #include "cached_value.h"
00016
00017 using namespace std;
00018
00019 namespace {
00020
00021
00022 bool check_throw(cached_value<bool> const & boolval)
00023 {
00024 bool foo;
00025 try {
00026 foo = boolval.get();
00027 foo = false;
00028 } catch (op_fatal_error const & e) {
00029 foo = true;
00030 }
00031 return foo;
00032 }
00033
00034
00035 int check_cached(void)
00036 {
00037 cached_value<bool> boolval;
00038 cached_value<string> strval;
00039
00040 if (!check_throw(boolval)) {
00041 cerr << "get() on no value didn't throw\n";
00042 return EXIT_FAILURE;
00043 }
00044
00045 if (boolval.reset(false) != false || boolval.get() != false) {
00046 cerr << "reset() of cached value \"false\" didn't work\n";
00047 return EXIT_FAILURE;
00048 }
00049
00050 if (boolval.reset(true) != true || boolval.get() != true) {
00051 cerr << "reset() of cached value \"true\" didn't work\n";
00052 return EXIT_FAILURE;
00053 }
00054
00055 if (strval.reset("foo") != "foo" || strval.get() != "foo") {
00056 cerr << "reset() of cached value \"foo\" didn't work\n";
00057 return EXIT_FAILURE;
00058 }
00059
00060 if (strval.reset("") != "" || strval.get() != "") {
00061 cerr << "reset() of cached value \"\" didn't work\n";
00062 return EXIT_FAILURE;
00063 }
00064
00065 return EXIT_SUCCESS;
00066 }
00067
00068 };
00069
00070 int main()
00071 {
00072 try {
00073 check_cached();
00074 }
00075 catch (...) {
00076 cerr << "unknown exception\n";
00077 return EXIT_FAILURE;
00078 }
00079
00080 return EXIT_SUCCESS;
00081 }