Fix several warnings that appear in gcc 4.3.2.
[wvstreams.git] / uniconf / t / uniretrygen.t.cc
blobace8153dfbc90fc038c588ea3203b0b4ef2858f5
1 #include "wvtest.h"
2 #include "uniconfroot.h"
3 #include "unitempgen.h"
4 #include "uniretrygen.h"
5 #include "uniclientgen.h"
6 #include "uniconfgen-sanitytest.h"
7 #include "wvfileutils.h"
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <signal.h>
14 struct UniRetryGenTester
16 WvString socket;
17 WvString ini;
18 pid_t uniconfd_pid;
19 UniRetryGenTester() :
20 socket("/tmp/uniretrygen-uniconfd-%s", getpid()),
21 ini("/tmp/uniretrygen-uniconfd.ini-%s", getpid()),
22 uniconfd_pid(0)
23 { }
27 void wait_for_daemon(UniRetryGenTester t)
29 UniConfRoot another_cfg(WvString("retry:unix:%s", t.socket));
31 for (;;)
33 another_cfg.xset("wait", "pong");
34 if (another_cfg.xget("wait") == "pong") break;
35 fprintf(stderr, "still waiting for connection.\n");
36 wvdelay(100);
39 fprintf(stderr, "managed to connect\n");
43 WVTEST_MAIN("UniRetryGen Sanity Test")
45 UniRetryGen *gen = new UniRetryGen("temp:");
46 UniConfGenSanityTester::sanity_test(gen, "retry:temp:");
47 WVRELEASE(gen);
50 WVTEST_MAIN("UniRetryGen: uniconfd")
52 signal(SIGPIPE, SIG_IGN);
54 UniRetryGenTester t;
56 unlink(t.ini);
58 UniConfRoot cfg(WvString("retry:unix:%s 100", t.socket));
59 cfg["/key"].setme("value");
60 WVPASS(!cfg["/key"].exists());
63 UniConfTestDaemon daemon(t.socket, WvString("ini:%s", t.ini));
64 wait_for_daemon(t);
66 wvdelay(100); // guarantee that the retry interval has expired
67 cfg["/key"].setme("value");
68 WVPASSEQ(cfg["/key"].getme(), "value");
70 cfg.commit();
73 // no delay necessary: we disconnect right away
74 WVPASS(!cfg["/key"].exists());
77 UniConfTestDaemon daemon(t.socket, WvString("ini:%s", t.ini));
78 wait_for_daemon(t);
80 wvdelay(100); // guarantee that the retry interval has expired
81 WVPASSEQ(cfg["/key"].getme(), "value");
83 cfg.commit();
86 WVPASS(!cfg["/key"].exists());
89 bool reconnected = false;
90 void reconnect_cb(UniRetryGen &uni)
91 { reconnected = true; }
93 WVTEST_MAIN("UniRetryGen: reconnect callback")
95 signal(SIGPIPE, SIG_IGN);
96 UniRetryGenTester t;
98 unlink(t.ini);
100 UniConfRoot cfg;
101 cfg.mountgen(new UniRetryGen(WvString("unix:%s", t.socket),
102 UniRetryGen::ReconnectCallback(reconnect_cb), 100));
104 reconnected = false;
106 UniConfTestDaemon daemon(t.socket, WvString("ini:%s", t.ini));
107 wait_for_daemon(t);
109 wvdelay(100); // guarantee that the retry interval has expired
110 cfg.getme(); // Do something to reconnect
111 WVPASS(reconnected);
114 WVTEST_MAIN("UniRetryGen: immediate reconnect")
116 signal(SIGPIPE, SIG_IGN);
118 UniRetryGenTester t;
120 unlink(t.ini);
122 // Need to set the reconnect delay to 0 to read immediately
123 UniConfRoot cfg(WvString("retry:unix:%s 0", t.socket));
126 UniConfTestDaemon daemon(t.socket, WvString("ini:%s", t.ini));
127 wait_for_daemon(t);
129 cfg["/key"].setme("value");
130 WVPASSEQ(cfg["/key"].getme(), "value");
132 cfg.commit();
135 // don't check anything before restarting so cfg doesn't know that
136 // uniconfd has disconnected.
138 UniConfTestDaemon daemon(t.socket, WvString("ini:%s", t.ini));
139 wait_for_daemon(t);
141 cfg.getme(); // Do something to reconnect
142 WVPASSEQ(cfg["/key"].getme(), "value");
145 WVPASS(!cfg["/key"].exists());
149 WVTEST_MAIN("UniRetryGen: mount point exists")
151 // bug 9769
152 UniConfRoot uniconf("temp:");
154 WVPASS(uniconf["foo"].mount("retry:unix:/tmp/foobar"));
156 WVPASS(uniconf["foo"].exists());
157 WVPASSEQ(uniconf["foo"].xget("", WvString::null), "");
159 WVFAIL(uniconf["foo/bar"].exists());
160 WVPASSEQ(uniconf["foo"].xget(""), WvString::null);