Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "common/wave_ex.h"
00036 #include "datahash/datahash_text.h"
00037 #include "dialog/dialog.h"
00038 #include "dialog/request.h"
00039 #include "perf/perf.h"
00040 #include "wave-crypto/wave-crypto.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049 class TestHost : public dialog::Host {
00050 public:
00051 ~TestHost(void) throw() { }
00052
00053
00054 void notifySubmit(IN const char * id,
00055 IN const Datahash * data) {
00056 DPRINTF("Just got submit, id='%s'", id);
00057 ASSERT2(data, "null");
00058 }
00059 };
00060
00061
00062
00063 static void
00064 doTest
00065 (
00066 IN int borderSize
00067 )
00068 {
00069
00070 dialog::ContainerRequest req;
00071
00072 req.addLabel("Hi there! This is a really long label! Yes! Maybe.... Yes again!");
00073 req.addLabel("This is a much smaller label");
00074 req.addButton("sub-1", "Button 1");
00075 req.addTextbox("txt-1", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26, false);
00076 req.addTextbox("txt-2", "abcdefghijklmnopqrstuvwxyz", 26, true);
00077 req.addLabel("ending label");
00078
00079 dialog::ContainerRequest subreq(dialog::ContainerRequest::eAxis_Horizontal);
00080 subreq.addLabel("horizontal");
00081 subreq.addButton("sub-2", "Button 2");
00082 subreq.addButton("sub-3", "Button 3");
00083 subreq.addTextbox("txt-3", "foobar", 6, false);
00084
00085 req.addContainer(subreq);
00086
00087 std::string data = req.get();
00088 DPRINTF("This is the dialog request string:\n%s", data.c_str());
00089
00090
00091 std::istringstream iss(data.c_str());
00092 smart_ptr<Datahash> hash = readHashFromStream("root", iss);
00093 ASSERT2(hash, "null");
00094
00095
00096
00097
00098 smart_ptr<crypto::DESKey> des = NULL;
00099
00100 smart_ptr<dialog::TextDrawer> drawer =
00101 dialog::TextDrawer::create(borderSize);
00102 ASSERT2(drawer, "null");
00103
00104 smart_ptr<dialog::Drawer> drawer2 = drawer;
00105 smart_ptr<dialog::Manager> mgr = dialog::Manager::create(des, drawer2);
00106 ASSERT2(mgr, "null");
00107
00108
00109 smart_ptr<TestHost> host = new TestHost;
00110 ASSERT2(host, "null");
00111
00112 ASSERT2(mgr->createDialog("test-1", 5, 20, hash, host),
00113 "Failed to create dialog");
00114
00115 mgr->display(1024, 768);
00116
00117 std::ostringstream oss;
00118 drawer->writeToStream(oss);
00119
00120 DPRINTF("Output dialog:\n%s", oss.str().c_str());
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 int
00132 main
00133 (
00134 IN int argc,
00135 IN const char * argv[]
00136 )
00137 {
00138 ASSERT(2 == argc,
00139 "Usage: dialog-test <border-size>");
00140 int borderSize = atoi(argv[1]);
00141 int retval = 0;
00142 try {
00143 perf::Timer timer("test -- overall timer");
00144 doTest(borderSize);
00145
00146 } catch (std::exception& e) {
00147 DPRINTF("Exception: %s", e.what());
00148 retval = 1;
00149 } catch (...) {
00150 DPRINTF("Unknown exception!");
00151 retval = 2;
00152 }
00153 perf::dumpTimingSummary(std::cerr);
00154
00155 return retval;
00156 }
00157