00001
00002 #include "mdclient.h"
00003
00004 using namespace std;
00005
00006 typedef struct _DE {
00007 char sig;
00008 const char * name; } newDEs;
00009
00010
00011 const char *predefinedObservables[5] = { "spintime", "omega-squared", "pressure", "temperature", "adsfasdf" };
00012 const char *randomValues[4] = { "333.333", "111.111", "34.43", "7777.777" };
00013 const char *requiredCmdSubSys[2] = { "SYSTEM", "STATUS" };
00014 string debug1,debug2,success("OK");
00015 newDEs otherP1Elements[6] = { {'d', "absorbance"}, {'d', "acceleration"},
00016 {'b', "_powered" }, {'t', "_uptime"},
00017 {'i', "_vacuum" }, {'d', "_rotorspeed"}
00018 };
00019
00020 void mdCoreAPITestSuite::bucket01(char const *title) {
00021
00022 phase = string("core API test bucket");
00023
00024 int nTests=(sizeof(predefinedObservables)/sizeof(char *)),variation;
00025 XmlRpcValue focus,gotten[nTests];
00026 cout << "\nTest Bucket: " << title << endl;
00027
00028
00029
00030 for ( variation=0; variation < nTests; variation++) {
00031
00032 cout << ".Get '" << predefinedObservables[variation] << "'\n";
00033 gotten[variation] = testState->get(mdServerHandle,predefinedObservables[variation]).getStruct();
00034 focus = gotten[variation].structGetValue("dataname");
00035 if (variation < (nTests - 1))
00036 TEST(focus.getString() == string(predefinedObservables[variation]));
00037 else TEST(focus.getString() == string("not found"));
00038
00039 }
00040
00041
00042
00043 for (variation=0;variation < (nTests - 1);variation++) {
00044 cout << ".Set '" << predefinedObservables[variation] << "'\n";
00045 gotten[variation].structSetValue("sValue",XmlRpcValue::makeString(randomValues[variation]));
00046 TEST(string("OK") == testState->set(mdServerHandle,gotten[variation]));
00047 }
00048
00049
00050
00051 for ( variation=0; variation < (nTests -1); variation++) {
00052
00053 cout << ".Cmp '" << predefinedObservables[variation] << "'\n";
00054 gotten[variation] = testState->get(mdServerHandle,predefinedObservables[variation]).getStruct();
00055 focus = gotten[variation].structGetValue("sValue");
00056 debug1 = focus.getString();
00057 debug2 = string(randomValues[variation]);
00058 TEST(focus.getString() == string(randomValues[variation]));
00059
00060 }
00061
00062 }
00063 void mdCoreAPITestSuite::bucket02(char const *title) {
00064
00065 int nRequired=(sizeof(requiredCmdSubSys)/sizeof(char *)),nthCmd=0,i,found=0;
00066 XmlRpcValue response;
00067 cout << "\nTest Bucket: " << title << endl;
00068
00069 response = testBehavior->getCommandList(mdServerHandle,string("")).getArray();
00070
00071 TEST(response.arraySize() >= nRequired);
00072
00073 for (nthCmd = 0; nthCmd < response.arraySize(); nthCmd++) {
00074 for (i=0;i<nRequired;i++)
00075 if (response.arrayGetItem(nthCmd).getString() == string(requiredCmdSubSys[i])) {
00076 cout << ".Has '" << requiredCmdSubSys[i] << "'\n";
00077 found++;
00078 }
00079 }
00080
00081 TEST(found == nRequired);
00082
00083 }
00084 void mdCoreAPITestSuite::bucket03(char const *title) {
00085
00086 int nNew=(sizeof(otherP1Elements)/sizeof(newDEs)),nthNew=0;
00087 std::string newType(" ");
00088 XmlRpcValue response;
00089 cout << "\nTest Bucket: " << title << endl;
00090
00091 for (;nthNew < nNew;nthNew++) {
00092
00093 cout << ".Add '" << otherP1Elements[nthNew].name
00094 << "' with signature: '" << otherP1Elements[nthNew].sig << "'\n";
00095 newType.replace(0,1,1,otherP1Elements[nthNew].sig);
00096 TEST(success == testState->create(mdServerHandle,newType,otherP1Elements[nthNew].name));
00097
00098 }
00099
00100 cout << "Note: you cannot run this bucket again without restarting MD." << endl;
00101
00102 }
00103 void mdCoreAPITestSuite::bucket04(char const *title) {
00104
00105 cout << "\nTest Bucket: " << title << " test variations not implemented yet." << endl;
00106
00107 }
00108 void mdCoreAPITestSuite::bucket05(char const *title) {
00109
00110 cout << "\nTest Bucket: " << title << " test variations not implemented yet." << endl;
00111
00112 }
00113 void mdCoreAPITestSuite::bucket06(char const *title) {
00114
00115 cout << "\nTest Bucket: " << title << " test variations not implemented yet.\n" << endl;
00116
00117 }