Py::Object removeSvgTags(const Py::Tuple& args) { const char* svgcode; if (!PyArg_ParseTuple(args.ptr(), "s",&svgcode)) throw Py::Exception(); std::string svg(svgcode); std::string empty = ""; std::string endline = "--endOfLine--"; std::string linebreak = "\\n"; // removing linebreaks for regex to work boost::regex e1 ("\\n"); svg = boost::regex_replace(svg, e1, endline); // removing starting xml definition boost::regex e2 ("<\\?xml.*?\\?>"); svg = boost::regex_replace(svg, e2, empty); // removing starting svg tag boost::regex e3 ("<svg.*?>"); svg = boost::regex_replace(svg, e3, empty); // removing sodipodi tags -- DANGEROUS, some sodipodi tags are single, better leave it //boost::regex e4 ("<sodipodi.*?>"); //svg = boost::regex_replace(svg, e4, empty); // removing metadata tags boost::regex e5 ("<metadata.*?</metadata>"); svg = boost::regex_replace(svg, e5, empty); // removing closing svg tags boost::regex e6 ("</svg>"); svg = boost::regex_replace(svg, e6, empty); // restoring linebreaks boost::regex e7 ("--endOfLine--"); svg = boost::regex_replace(svg, e7, linebreak); Py::String result(svg); return result; }
main() { Citygraph g; Cityvertex v[6]; Map<String,Vptr> m; m["SFRAN"] = &v[0]; v[0].id = "SFRAN"; m["LA"] = &v[1]; v[1].id = "LA"; m["CHGO"] = &v[2]; v[2].id = "CHGO"; m["DLLS"] = &v[3]; v[3].id = "DLLS"; m["BOST"] = &v[4]; v[4].id = "BOST"; m["NYC"] = &v[5]; v[5].id = "NYC"; Cityedge e0(m["CHGO"], m["BOST"], 0); Cityedge e1(m["SFRAN"], m["LA"], 1); Cityedge e2(m["LA"], m["SFRAN"], 2); Cityedge e3(m["SFRAN"], m["CHGO"], 3); Cityedge e4(m["SFRAN"], m["NYC"], 4); Cityedge e5(m["SFRAN"], m["BOST"], 5); Cityedge e6(m["BOST"], m["SFRAN"], 6); Cityedge e7(m["NYC"], m["SFRAN"], 7); Cityedge e8(m["CHGO"], m["SFRAN"], 8); Cityedge e9(m["DLLS"], m["NYC"], 9); Cityedge e10(m["BOST"], m["LA"], 10); g.insert(&e0); g.insert(&e1); g.insert(&e2); g.insert(&e3); g.insert(&e4); g.insert(&e5); g.insert(&e6); g.insert(&e7); g.insert(&e8); g.insert(&e9); g.insert(&e10); Set_of_p<Cityvertex> vpset; vpset.insert(m["SFRAN"]); vpset.insert(m["LA"]); vpset.insert(m["BOST"]); vpset.insert(m["NYC"]); vpset.insert(m["CHGO"]); Citygraph g2 = g.induced_graph(vpset); //create the subgraph of these Vertices and appropriate Edges // Now let's verify what is in the newly-created subgraph for (int i = 0; i < 6; i++) cout << v[i].id << ": " << g2.contains(&v[i]) << "\n" << flush; cout << "e with id " << e0.id << ": "<< g2.contains(&e0)<< "\n"<< flush; cout << "e with id " << e1.id << ": "<< g2.contains(&e1)<< "\n"<< flush; cout << "e with id " << e2.id << ": "<< g2.contains(&e2)<< "\n"<< flush; cout << "e with id " << e3.id << ": "<< g2.contains(&e3)<< "\n"<< flush; cout << "e with id " << e4.id << ": "<< g2.contains(&e4)<< "\n"<< flush; cout << "e with id " << e5.id << ": "<< g2.contains(&e5)<< "\n"<< flush; cout << "e with id " << e6.id << ": "<< g2.contains(&e6)<< "\n"<< flush; cout << "e with id " << e7.id << ": "<< g2.contains(&e7)<< "\n"<< flush; cout << "e with id " << e8.id << ": "<< g2.contains(&e8)<< "\n"<< flush; cout << "e with id " << e9.id << ": "<< g2.contains(&e9)<< "\n"<< flush; cout << "e with id " << e10.id << ": "<< g2.contains(&e10)<< "\n"<< flush; return(0); }
int main (int argc, char** argv) { UnitTest t (211); // Ensure environment has no influence. unsetenv ("TASKDATA"); unsetenv ("TASKRC"); try { Date now; Date yesterday; yesterday -= 86400; Date tomorrow; tomorrow += 86400; t.ok (yesterday <= now, "yesterday <= now"); t.ok (yesterday < now, "yesterday < now"); t.notok (yesterday == now, "!(yesterday == now)"); t.ok (yesterday != now, "yesterday != now"); t.ok (now >= yesterday, "now >= yesterday"); t.ok (now > yesterday, "now > yesterday"); t.ok (tomorrow >= now, "tomorrow >= now"); t.ok (tomorrow > now, "tomorrow > now"); t.notok (tomorrow == now, "!(tomorrow == now)"); t.ok (tomorrow != now, "tomorrow != now"); t.ok (now <= tomorrow, "now <= tomorrow"); t.ok (now < tomorrow, "now < tomorrow"); // Date::Date ("now") context.config.set ("weekstart", "monday"); Date relative_now ("now"); t.ok (relative_now.sameHour (now), "Date ().sameHour (Date (now))"); t.ok (relative_now.sameDay (now), "Date ().sameDay (Date (now))"); t.ok (relative_now.sameWeek (now), "Date ().sameWeek (Date (now))"); t.ok (relative_now.sameMonth (now), "Date ().sameMonth (Date (now))"); t.ok (relative_now.sameYear (now), "Date ().sameYear (Date (now))"); // Loose comparisons. Date left ("7/4/2008"); Date comp1 ("7/4/2008"); t.ok (left.sameDay (comp1), "7/4/2008 is on the same day as 7/4/2008"); t.ok (left.sameWeek (comp1), "7/4/2008 is on the same week as 7/4/2008"); t.ok (left.sameMonth (comp1), "7/4/2008 is in the same month as 7/4/2008"); t.ok (left.sameYear (comp1), "7/4/2008 is in the same year as 7/4/2008"); Date comp2 ("7/5/2008"); t.notok (left.sameDay (comp2), "7/4/2008 is not on the same day as 7/5/2008"); t.ok (left.sameMonth (comp2), "7/4/2008 is in the same month as 7/5/2008"); t.ok (left.sameYear (comp2), "7/4/2008 is in the same year as 7/5/2008"); Date comp3 ("8/4/2008"); t.notok (left.sameDay (comp3), "7/4/2008 is not on the same day as 8/4/2008"); t.notok (left.sameWeek (comp3), "7/4/2008 is not on the same week as 8/4/2008"); t.notok (left.sameMonth (comp3), "7/4/2008 is not in the same month as 8/4/2008"); t.ok (left.sameYear (comp3), "7/4/2008 is in the same year as 8/4/2008"); Date comp4 ("7/4/2009"); t.notok (left.sameDay (comp4), "7/4/2008 is not on the same day as 7/4/2009"); t.notok (left.sameWeek (comp3), "7/4/2008 is not on the same week as 7/4/2009"); t.notok (left.sameMonth (comp4), "7/4/2008 is not in the same month as 7/4/2009"); t.notok (left.sameYear (comp4), "7/4/2008 is not in the same year as 7/4/2009"); // Validity. t.ok (Date::valid (2, 29, 2008), "valid: 2/29/2008"); t.notok (Date::valid (2, 29, 2007), "invalid: 2/29/2007"); t.ok (Date::valid ("2/29/2008"), "valid: 2/29/2008"); t.notok (Date::valid ("2/29/2007"), "invalid: 2/29/2007"); t.ok (Date::valid (366, 2008), "valid: 366 days in 2008"); t.notok (Date::valid (366, 2007), "invalid: 366 days in 2007"); // Time validity. t.ok (Date::valid (2, 28, 2010, 0, 0, 0), "valid 2/28/2010 0:00:00"); t.ok (Date::valid (2, 28, 2010, 23, 59, 59), "valid 2/28/2010 23:59:59"); t.notok (Date::valid (2, 28, 2010, 24, 59, 59), "valid 2/28/2010 24:59:59"); t.notok (Date::valid (2, 28, 2010, -1, 0, 0), "valid 2/28/2010 -1:00:00"); // Leap year. t.ok (Date::leapYear (2008), "2008 is a leap year"); t.notok (Date::leapYear (2007), "2007 is not a leap year"); t.ok (Date::leapYear (2000), "2000 is a leap year"); t.notok (Date::leapYear (1900), "1900 is not a leap year"); // Days in month. t.is (Date::daysInMonth (2, 2008), 29, "29 days in February 2008"); t.is (Date::daysInMonth (2, 2007), 28, "28 days in February 2007"); // Names. t.is (Date::monthName (1), "January", "1 = January"); t.is (Date::monthName (2), "February", "2 = February"); t.is (Date::monthName (3), "March", "3 = March"); t.is (Date::monthName (4), "April", "4 = April"); t.is (Date::monthName (5), "May", "5 = May"); t.is (Date::monthName (6), "June", "6 = June"); t.is (Date::monthName (7), "July", "7 = July"); t.is (Date::monthName (8), "August", "8 = August"); t.is (Date::monthName (9), "September", "9 = September"); t.is (Date::monthName (10), "October", "10 = October"); t.is (Date::monthName (11), "November", "11 = November"); t.is (Date::monthName (12), "December", "12 = December"); t.is (Date::dayName (0), "Sunday", "0 == Sunday"); t.is (Date::dayName (1), "Monday", "1 == Monday"); t.is (Date::dayName (2), "Tuesday", "2 == Tuesday"); t.is (Date::dayName (3), "Wednesday", "3 == Wednesday"); t.is (Date::dayName (4), "Thursday", "4 == Thursday"); t.is (Date::dayName (5), "Friday", "5 == Friday"); t.is (Date::dayName (6), "Saturday", "6 == Saturday"); t.is (Date::dayOfWeek ("SUNDAY"), 0, "SUNDAY == 0"); t.is (Date::dayOfWeek ("sunday"), 0, "sunday == 0"); t.is (Date::dayOfWeek ("Sunday"), 0, "Sunday == 0"); t.is (Date::dayOfWeek ("Monday"), 1, "Monday == 1"); t.is (Date::dayOfWeek ("Tuesday"), 2, "Tuesday == 2"); t.is (Date::dayOfWeek ("Wednesday"), 3, "Wednesday == 3"); t.is (Date::dayOfWeek ("Thursday"), 4, "Thursday == 4"); t.is (Date::dayOfWeek ("Friday"), 5, "Friday == 5"); t.is (Date::dayOfWeek ("Saturday"), 6, "Saturday == 6"); Date happyNewYear (1, 1, 2008); t.is (happyNewYear.dayOfWeek (), 2, "1/1/2008 == Tuesday"); t.is (happyNewYear.month (), 1, "1/1/2008 == January"); t.is (happyNewYear.day (), 1, "1/1/2008 == 1"); t.is (happyNewYear.year (), 2008, "1/1/2008 == 2008"); t.is (happyNewYear.toString (), "1/1/2008", "toString 1/1/2008"); int m, d, y; happyNewYear.toMDY (m, d, y); t.is (m, 1, "1/1/2008 == January"); t.is (d, 1, "1/1/2008 == 1"); t.is (y, 2008, "1/1/2008 == 2008"); Date epoch (9, 8, 2001); t.ok ((int)epoch.toEpoch () < 1000000000, "9/8/2001 < 1,000,000,000"); epoch += 172800; t.ok ((int)epoch.toEpoch () > 1000000000, "9/10/2001 > 1,000,000,000"); Date fromEpoch (epoch.toEpoch ()); t.is (fromEpoch.toString (), epoch.toString (), "ctor (time_t)"); Date iso (1000000000); t.is (iso.toISO (), "20010909T014640Z", "1,000,000,000 -> 20010909T014640Z"); // Quantization. Date quant (1234526400); t.is (quant.startOfDay ().toString ("YMDHNS"), "20090213000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/13/2009 0:00:00"); t.is (quant.startOfWeek ().toString ("YMDHNS"), "20090208000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/8/2009 0:00:00"); t.is (quant.startOfMonth ().toString ("YMDHNS"), "20090201000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 2/1/2009 0:00:00"); t.is (quant.startOfYear ().toString ("YMDHNS"), "20090101000000", "1234526400 -> 2/13/2009 12:00:00 UTC -> 1/1/2009 0:00:00"); // Date parsing. Date fromString1 ("1/1/2008"); t.is (fromString1.month (), 1, "ctor (std::string) -> m"); t.is (fromString1.day (), 1, "ctor (std::string) -> d"); t.is (fromString1.year (), 2008, "ctor (std::string) -> y"); Date fromString2 ("1/1/2008", "m/d/Y"); t.is (fromString2.month (), 1, "ctor (std::string) -> m"); t.is (fromString2.day (), 1, "ctor (std::string) -> d"); t.is (fromString2.year (), 2008, "ctor (std::string) -> y"); Date fromString3 ("20080101", "YMD"); t.is (fromString3.month (), 1, "ctor (std::string) -> m"); t.is (fromString3.day (), 1, "ctor (std::string) -> d"); t.is (fromString3.year (), 2008, "ctor (std::string) -> y"); Date fromString4 ("12/31/2007"); t.is (fromString4.month (), 12, "ctor (std::string) -> m"); t.is (fromString4.day (), 31, "ctor (std::string) -> d"); t.is (fromString4.year (), 2007, "ctor (std::string) -> y"); Date fromString5 ("12/31/2007", "m/d/Y"); t.is (fromString5.month (), 12, "ctor (std::string) -> m"); t.is (fromString5.day (), 31, "ctor (std::string) -> d"); t.is (fromString5.year (), 2007, "ctor (std::string) -> y"); Date fromString6 ("20071231", "YMD"); t.is (fromString6.month (), 12, "ctor (std::string) -> m"); t.is (fromString6.day (), 31, "ctor (std::string) -> d"); t.is (fromString6.year (), 2007, "ctor (std::string) -> y"); Date fromString7 ("01/01/2008", "m/d/Y"); t.is (fromString7.month (), 1, "ctor (std::string) -> m"); t.is (fromString7.day (), 1, "ctor (std::string) -> d"); t.is (fromString7.year (), 2008, "ctor (std::string) -> y"); Date fromString8 ("Tue 05 Feb 2008 (06)", "a D b Y (V)"); t.is (fromString8.month (), 2, "ctor (std::string) -> m"); t.is (fromString8.day (), 5, "ctor (std::string) -> d"); t.is (fromString8.year (), 2008, "ctor (std::string) -> y"); Date fromString9 ("Tuesday, February 5, 2008", "A, B d, Y"); t.is (fromString9.month (), 2, "ctor (std::string) -> m"); t.is (fromString9.day (), 5, "ctor (std::string) -> d"); t.is (fromString9.year (), 2008, "ctor (std::string) -> y"); Date fromString10 ("w01 Tue 2008-01-01", "wV a Y-M-D"); t.is (fromString10.month (), 1, "ctor (std::string) -> m"); t.is (fromString10.day (), 1, "ctor (std::string) -> d"); t.is (fromString10.year (), 2008, "ctor (std::string) -> y"); Date fromString11 ("6/7/2010 1:23:45", "m/d/Y h:N:S"); t.is (fromString11.month (), 6, "ctor (std::string) -> m"); t.is (fromString11.day (), 7, "ctor (std::string) -> d"); t.is (fromString11.year (), 2010, "ctor (std::string) -> Y"); t.is (fromString11.hour (), 1, "ctor (std::string) -> h"); t.is (fromString11.minute (), 23, "ctor (std::string) -> N"); t.is (fromString11.second (), 45, "ctor (std::string) -> S"); Date fromString12 ("6/7/2010 01:23:45", "m/d/Y H:N:S"); t.is (fromString12.month (), 6, "ctor (std::string) -> m"); t.is (fromString12.day (), 7, "ctor (std::string) -> d"); t.is (fromString12.year (), 2010, "ctor (std::string) -> Y"); t.is (fromString12.hour (), 1, "ctor (std::string) -> h"); t.is (fromString12.minute (), 23, "ctor (std::string) -> N"); t.is (fromString12.second (), 45, "ctor (std::string) -> S"); Date fromString13 ("6/7/2010 12:34:56", "m/d/Y H:N:S"); t.is (fromString13.month (), 6, "ctor (std::string) -> m"); t.is (fromString13.day (), 7, "ctor (std::string) -> d"); t.is (fromString13.year (), 2010, "ctor (std::string) -> Y"); t.is (fromString13.hour (), 12, "ctor (std::string) -> h"); t.is (fromString13.minute (), 34, "ctor (std::string) -> N"); t.is (fromString13.second (), 56, "ctor (std::string) -> S"); // Day of year t.is (Date ("1/1/2011", "m/d/Y").dayOfYear (), 1, "dayOfYear (1/1/2011) -> 1"); t.is (Date ("5/1/2011", "m/d/Y").dayOfYear (), 121, "dayOfYear (5/1/2011) -> 121"); t.is (Date ("12/31/2011", "m/d/Y").dayOfYear (), 365, "dayOfYear (12/31/2011) -> 365"); // Easter Date e1 (Date::easter(1980)); t.is (e1.toString (), "4/6/1980", "Easter 4/6/1980"); Date e2 (Date::easter(1995)); t.is (e2.toString (), "4/16/1995", "Easter 4/16/1995"); Date e3 (Date::easter(2000)); t.is (e3.toString (), "4/23/2000", "Easter 4/23/2000"); Date e4 (Date::easter(2009)); t.is (e4.toString (), "4/12/2009", "Easter 4/12/2009"); Date e5 (Date::easter(2010)); t.is (e5.toString (), "4/4/2010", "Easter 4/4/2010"); Date e6 (Date::easter(2011)); t.is (e6.toString (), "4/24/2011", "Easter 4/24/2011"); Date e7 (Date::easter(2012)); t.is (e7.toString (), "4/8/2012", "Easter 4/8/2012"); Date e8 (Date::easter(2020)); t.is (e8.toString (), "4/12/2020", "Easter 4/12/2020"); // Relative dates. Date r1 ("today"); t.ok (r1.sameDay (now), "today = now"); Date r4 ("sunday"); if (now.dayOfWeek () >= 0) t.ok (r4.sameDay (now + (0 - now.dayOfWeek () + 7) * 86400), "next sunday"); else t.ok (r4.sameDay (now + (0 - now.dayOfWeek ()) * 86400), "next sunday");; Date r5 ("monday"); if (now.dayOfWeek () >= 1) t.ok (r5.sameDay (now + (1 - now.dayOfWeek () + 7) * 86400), "next monday"); else t.ok (r5.sameDay (now + (1 - now.dayOfWeek ()) * 86400), "next monday");; Date r6 ("tuesday"); if (now.dayOfWeek () >= 2) t.ok (r6.sameDay (now + (2 - now.dayOfWeek () + 7) * 86400), "next tuesday"); else t.ok (r6.sameDay (now + (2 - now.dayOfWeek ()) * 86400), "next tuesday");; Date r7 ("wednesday"); if (now.dayOfWeek () >= 3) t.ok (r7.sameDay (now + (3 - now.dayOfWeek () + 7) * 86400), "next wednesday"); else t.ok (r7.sameDay (now + (3 - now.dayOfWeek ()) * 86400), "next wednesday");; Date r8 ("thursday"); if (now.dayOfWeek () >= 4) t.ok (r8.sameDay (now + (4 - now.dayOfWeek () + 7) * 86400), "next thursday"); else t.ok (r8.sameDay (now + (4 - now.dayOfWeek ()) * 86400), "next thursday");; Date r9 ("friday"); if (now.dayOfWeek () >= 5) t.ok (r9.sameDay (now + (5 - now.dayOfWeek () + 7) * 86400), "next friday"); else t.ok (r9.sameDay (now + (5 - now.dayOfWeek ()) * 86400), "next friday");; Date r10 ("saturday"); if (now.dayOfWeek () >= 6) t.ok (r10.sameDay (now + (6 - now.dayOfWeek () + 7) * 86400), "next saturday"); else t.ok (r10.sameDay (now + (6 - now.dayOfWeek ()) * 86400), "next saturday");; Date r11 ("eow"); t.ok (r11 < now + (8 * 86400), "eow < 7 days away"); Date r12 ("eocw"); t.ok (r12 > now - (8 * 86400), "eocw < 7 days in the past"); Date r13 ("eom"); t.ok (r13.sameMonth (now), "eom in same month as now"); Date r14 ("eocm"); t.ok (r14.sameMonth (now), "eocm in same month as now"); Date r15 ("eoy"); t.ok (r15.sameYear (now), "eoy in same year as now"); Date r16 ("sow"); t.ok (r16 < now + (8 * 86400), "sow < 7 days away"); Date r23 ("socw"); t.ok (r23 > now - (8 * 86400), "sow < 7 days in the past"); Date r17 ("som"); t.notok (r17.sameMonth (now), "som not in same month as now"); Date r18 ("socm"); t.ok (r18.sameMonth (now), "socm in same month as now"); Date r19 ("soy"); t.notok (r19.sameYear (now), "soy not in same year as now"); Date first ("1st"); t.notok (first.sameMonth (now), "1st not in same month as now"); t.is (first.day (), 1, "1st day is 1"); Date later ("later"); t.is (later.month (), 1, "later -> m = 1"); t.is (later.day (), 18, "later -> d = 18"); t.is (later.year (), 2038, "later -> y = 2038"); // Quarters Date soq ("soq"); Date eoq ("eoq"); t.is (soq.day (), 1, "soq is the first day of a month"); t.is (eoq.day () / 10, 3, "eoq is the 30th or 31th of a month"); t.is (soq.month () % 3, 1, "soq month is 1, 4, 7 or 10"); t.is (eoq.month () % 3, 0, "eoq month is 3, 6, 9 or 12"); // Note: these fail during the night of daylight savings end. t.ok (soq.sameYear (now) || (now.month () >= 10 && soq.year () == now.year () + 1), "soq is in same year as now"); t.ok (eoq.sameYear (now), "eoq is in same year as now"); // Date::sameHour Date r20 ("6/7/2010 01:00:00", "m/d/Y H:N:S"); Date r21 ("6/7/2010 01:59:59", "m/d/Y H:N:S"); t.ok (r20.sameHour (r21), "two dates within the same hour"); Date r22 ("6/7/2010 00:59:59", "m/d/Y H:N:S"); t.notok (r20.sameHour (r22), "two dates not within the same hour"); // Date::operator- Date r25 (1234567890); t.is ((r25 - 1).toEpoch (), 1234567889, "1234567890 - 1 = 1234567889"); // Date::operator-- Date r26 (11, 7, 2010, 23, 59, 59); r26--; t.is (r26.toString ("YMDHNS"), "20101106235959", "decrement across fall DST boundary"); Date r27 (3, 14, 2010, 23, 59, 59); r27--; t.is (r27.toString ("YMDHNS"), "20100313235959", "decrement across spring DST boundary"); // Date::operator++ Date r28 (11, 6, 2010, 23, 59, 59); r28++; t.is (r28.toString ("YMDHNS"), "20101107235959", "increment across fall DST boundary"); Date r29 (3, 13, 2010, 23, 59, 59); r29++; t.is (r29.toString ("YMDHNS"), "20100314235959", "increment across spring DST boundary"); // int Date::length (const std::string&); t.is (Date::length ("m"), 2, "length 'm' --> 2"); t.is (Date::length ("M"), 2, "length 'M' --> 2"); t.is (Date::length ("d"), 2, "length 'd' --> 2"); t.is (Date::length ("D"), 2, "length 'D' --> 2"); t.is (Date::length ("y"), 2, "length 'y' --> 2"); t.is (Date::length ("Y"), 4, "length 'Y' --> 4"); t.is (Date::length ("a"), 3, "length 'a' --> 3"); t.is (Date::length ("A"), 10, "length 'A' --> 10"); t.is (Date::length ("b"), 3, "length 'b' --> 3"); t.is (Date::length ("B"), 10, "length 'B' --> 10"); t.is (Date::length ("v"), 2, "length 'v' --> 2"); t.is (Date::length ("V"), 2, "length 'V' --> 2"); t.is (Date::length ("h"), 2, "length 'h' --> 2"); t.is (Date::length ("H"), 2, "length 'H' --> 2"); t.is (Date::length ("n"), 2, "length 'n' --> 2"); t.is (Date::length ("N"), 2, "length 'N' --> 2"); t.is (Date::length ("s"), 2, "length 's' --> 2"); t.is (Date::length ("S"), 2, "length 'S' --> 2"); t.is (Date::length ("j"), 3, "length 'j' --> 3"); t.is (Date::length ("J"), 3, "length 'J' --> 3"); t.is (Date::length (" "), 1, "length ' ' --> 1"); // Depletion requirement. Date r30 ("Mon Jun 30 2014", "a b D Y", false, false); t.is (r30.toString ("YMDHNS"), "20140630000000", "Depletion required on complex format with spaces"); std::string::size_type i = 0; Date r31 ("Mon Jun 30 2014 xxx", i, "a b D Y", false, false); t.is (r31.toString ("YMDHNS"), "20140630000000", "Depletion not required on complex format with spaces"); t.is ((int)i, 15, "Depletion not required on complex format with spaces, 15 chars"); } catch (const std::string& e) { t.fail ("Exception thrown."); t.diag (e); } return 0; }
void drive_operation() { // Uint64 tests CQLValue a1(Uint64(10)); CQLValue a2(Uint64(15)); CQLValue a3(Uint64(25)); CQLValue a4(Uint64(30)); CQLValue a5(Uint64(150)); PEGASUS_TEST_ASSERT(a1 != a2); PEGASUS_TEST_ASSERT(a5 == a5); PEGASUS_TEST_ASSERT(a1 < a2); PEGASUS_TEST_ASSERT(a2 >= a1); PEGASUS_TEST_ASSERT(a1 <= a2); PEGASUS_TEST_ASSERT(a2 > a1); // Sint64 tests CQLValue b1(Sint64(10)); CQLValue b2(Sint64(15)); CQLValue b3(Sint64(25)); CQLValue b4(Sint64(30)); CQLValue b5(Sint64(150)); PEGASUS_TEST_ASSERT(b1 != b2); PEGASUS_TEST_ASSERT(b5 == b5); PEGASUS_TEST_ASSERT(b1 < b2); PEGASUS_TEST_ASSERT(b2 >= b1); PEGASUS_TEST_ASSERT(b1 <= b2); PEGASUS_TEST_ASSERT(b2 > b1); // Real64 tests CQLValue c1(Real64(10.00)); CQLValue c2(Real64(15.00)); CQLValue c3(Real64(25.00)); CQLValue c4(Real64(30.00)); CQLValue c5(Real64(150.00)); PEGASUS_TEST_ASSERT(c1 != c2); PEGASUS_TEST_ASSERT(c5 == c5); PEGASUS_TEST_ASSERT(c1 < c2); PEGASUS_TEST_ASSERT(c2 >= c1); PEGASUS_TEST_ASSERT(c1 <= c2); PEGASUS_TEST_ASSERT(c2 > c1); // Misc PEGASUS_TEST_ASSERT(a1 == b1); PEGASUS_TEST_ASSERT(a1 == c1); PEGASUS_TEST_ASSERT(b1 == a1); PEGASUS_TEST_ASSERT(b1 == c1); PEGASUS_TEST_ASSERT(c1 == a1); PEGASUS_TEST_ASSERT(c1 == b1); PEGASUS_TEST_ASSERT(a2 != b1); PEGASUS_TEST_ASSERT(a2 != c1); PEGASUS_TEST_ASSERT(b2 != a1); PEGASUS_TEST_ASSERT(b2 != c1); PEGASUS_TEST_ASSERT(c2 != a1); PEGASUS_TEST_ASSERT(c2 != b1); PEGASUS_TEST_ASSERT(a2 >= b1); PEGASUS_TEST_ASSERT(a2 >= c1); PEGASUS_TEST_ASSERT(b2 >= a1); PEGASUS_TEST_ASSERT(b2 >= c1); PEGASUS_TEST_ASSERT(c2 >= a1); PEGASUS_TEST_ASSERT(c2 >= b1); PEGASUS_TEST_ASSERT(a2 <= b3); PEGASUS_TEST_ASSERT(a2 <= c3); PEGASUS_TEST_ASSERT(b2 <= a3); PEGASUS_TEST_ASSERT(b2 <= c3); PEGASUS_TEST_ASSERT(c2 <= a3); PEGASUS_TEST_ASSERT(c2 <= b3); PEGASUS_TEST_ASSERT(a2 > b1); PEGASUS_TEST_ASSERT(a2 > c1); PEGASUS_TEST_ASSERT(b2 > a1); PEGASUS_TEST_ASSERT(b2 > c1); PEGASUS_TEST_ASSERT(c2 > a1); PEGASUS_TEST_ASSERT(c2 > b1); PEGASUS_TEST_ASSERT(a2 < b3); PEGASUS_TEST_ASSERT(a2 < c3); PEGASUS_TEST_ASSERT(b2 < a3); PEGASUS_TEST_ASSERT(b2 < c3); PEGASUS_TEST_ASSERT(c2 < a3); PEGASUS_TEST_ASSERT(c2 < b3); //Overflow testing CQLValue real1(Real64(0.00000001)); CQLValue sint1(Sint64(-1)); CQLValue uint1(Sint64(1)); CQLValue uint2(Uint64(0)); PEGASUS_TEST_ASSERT(uint1 > sint1); PEGASUS_TEST_ASSERT(real1 > sint1); PEGASUS_TEST_ASSERT(uint2 > sint1); PEGASUS_TEST_ASSERT(real1 > uint2); CQLValue real2(Real64(25.00000000000001)); CQLValue real3(Real64(24.99999999999999)); CQLValue sint2(Sint64(25)); CQLValue uint3(Uint64(25)); PEGASUS_TEST_ASSERT(real2 > real3); PEGASUS_TEST_ASSERT(real2 > sint2); PEGASUS_TEST_ASSERT(real2 > uint3); PEGASUS_TEST_ASSERT(real3 < sint2); PEGASUS_TEST_ASSERT(real3 < uint3); // String tests CQLValue d1(String("HELLO")); CQLValue d2(String("HEL")); CQLValue d3(String("LO")); CQLValue d4(String("AHELLO")); CQLValue d5(String("ZHELLO")); PEGASUS_TEST_ASSERT(d1 == d2 + d3); PEGASUS_TEST_ASSERT(d1 != d2 + d4); PEGASUS_TEST_ASSERT(d1 <= d5); PEGASUS_TEST_ASSERT(d1 < d5); PEGASUS_TEST_ASSERT(d1 >= d4); PEGASUS_TEST_ASSERT(d1 > d4); String str1("0x10"); String str2("10"); String str3("10B"); String str4("10.10"); CQLValue e1( str1, CQLValue::Hex); CQLValue e2( str2, CQLValue::Decimal); CQLValue e3( str3, CQLValue::Binary); CQLValue e4( str4, CQLValue::Real); CQLValue e5(Uint64(16)); CQLValue e6(Uint64(10)); CQLValue e7(Uint64(2)); CQLValue e8(Real64(10.10)); PEGASUS_TEST_ASSERT(e1 == e5); PEGASUS_TEST_ASSERT(e2 == e6); PEGASUS_TEST_ASSERT(e3 == e7); PEGASUS_TEST_ASSERT(e4 == e8); Array<Uint64> array1; array1.append(1); array1.append(2); array1.append(3); array1.append(4); array1.append(5); array1.append(6); array1.append(7); array1.append(8); array1.append(9); array1.append(10); Array<Sint64> array2; array2.append(1); array2.append(2); array2.append(3); array2.append(4); array2.append(5); array2.append(6); array2.append(7); array2.append(8); array2.append(9); array2.append(10); array2.append(3); Array<Real64> array3; array3.append(1.00); array3.append(2.00); array3.append(3.00); array3.append(9.00); array3.append(10.00); array3.append(3.00); array3.append(4.00); array3.append(5.00); array3.append(6.00); array3.append(7.00); array3.append(8.00); Array<Uint64> array4; array4.append(1); array4.append(23); array4.append(3); array4.append(4); array4.append(5); array4.append(6); array4.append(7); array4.append(88); array4.append(9); array4.append(10); Array<Sint64> array5; array5.append(-1); array5.append(2); array5.append(3); array5.append(4); array5.append(5); array5.append(-6); array5.append(7); array5.append(8); array5.append(9); array5.append(10); array5.append(-3); Array<Real64> array6; array6.append(1.23); array6.append(2.00); array6.append(3.00); array6.append(9.00); array6.append(10.00); array6.append(3.00); array6.append(4.14); array6.append(5.00); array6.append(6.00); array6.append(7.00); array6.append(8.00); CIMValue cv1(array1); CIMValue cv2(array2); CIMValue cv3(array3); CIMValue cv4(array4); CIMValue cv5(array5); CIMValue cv6(array6); CQLValue vr1(cv1); CQLValue vr2(cv1); CQLValue vr3(cv2); CQLValue vr4(cv3); CQLValue vr5(cv4); CQLValue vr6(cv5); CQLValue vr7(cv6); PEGASUS_TEST_ASSERT(vr1 == vr2); PEGASUS_TEST_ASSERT(vr1 == vr3); PEGASUS_TEST_ASSERT(vr1 == vr4); PEGASUS_TEST_ASSERT(vr4 == vr3); PEGASUS_TEST_ASSERT(vr1 != vr5); PEGASUS_TEST_ASSERT(vr3 != vr6); PEGASUS_TEST_ASSERT(vr4 != vr7); const CIMName _cimName(String("CIM_OperatingSystem")); CIMInstance _i1(_cimName); CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules"))); CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2))); CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600))); CIMProperty _p4(CIMName("TimeOfLastStateChange"), CIMValue(CIMDateTime(String("20040811105625.000000-360")))); _i1.addProperty(_p1); _i1.addProperty(_p2); _i1.addProperty(_p3); _i1.addProperty(_p4); CIMInstance _i2(_cimName); CIMProperty _p5(CIMName("Description"), CIMValue(String("Dave Rules Everything"))); CIMProperty _p6(CIMName("EnabledState"),CIMValue(Uint16(2))); CIMProperty _p7(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600))); CIMProperty _p8(CIMName("TimeOfLastStateChange"), CIMValue(CIMDateTime(String("20040811105625.000000-360")))); _i2.addProperty(_p5); _i2.addProperty(_p6); _i2.addProperty(_p7); _i2.addProperty(_p8); CQLValue cql1(_i1); CQLValue cql2(_i1); CQLValue cql3(_i2); CQLValue cql4(_i2); //PEGASUS_TEST_ASSERT(cql1 == cql1); return; }
int json_cpp_tests() { json::Value e1(json::load_file("test.json")); json::Value e2(e1); json::Value e3; json::Value e4(json::load_string("{\"foo\": true, \"bar\": \"test\"}")); ASSERT_TRUE(e1.is_object(), "e1 is not an object"); ASSERT_TRUE(e2.is_object(), "e2 is not an object"); ASSERT_TRUE(e3.is_undefined(), "e3 has a defined value"); ASSERT_TRUE(e4.is_object(), "e4 is not an object"); ASSERT_EQ(e1.size(), 1, "e1 has too many properties"); ASSERT_EQ(e2.size(), 1, "e2 has too many properties"); ASSERT_EQ(e4.size(), 2, "e4 does not have 2 elements"); ASSERT_TRUE(e1.get("web-app").is_object(), "e1[0].web-app is not an object"); ASSERT_EQ(e1.get("web-app").get("servlet").at(0).get("servlet-class").as_string(), "org.cofax.cds.CDSServlet", "property has incorrect value"); ASSERT_EQ(e1["web-app"]["servlet"][0]["servlet-class"].as_string(), "org.cofax.cds.CDSServlet", "property has incorrect value"); ASSERT_EQ(e4["foo"].as_boolean(), true, "property has incorrect value"); // verify iterator results (note that they can be returned in any order) json::Iterator i(e1.get("web-app")); std::set<std::string> iteratorResults; for ( int ii = 0; ii < 3; ++ii ) { ASSERT_FALSE(i.key().empty(), "iterator returned a null value"); iteratorResults.insert(i.key()); i.next(); } ASSERT_FALSE(i.valid(), "iterator has more values than expected"); ASSERT_EQ(iteratorResults.size(), 3, "iterator did not return enough values"); json::Value e5(json::Value(12.34)); ASSERT_TRUE(e5.is_number(), "e5 is not a number after assignment"); ASSERT_EQ(e5.as_real(), 12.34, "e5 has incorrect value after assignment"); json::Value e6(json::Value(true)); ASSERT_TRUE(e6.is_boolean(), "e6 is not a boolean after assignment"); ASSERT_EQ(e6.as_boolean(), true, "e6 has incorrect value after assignment"); json::Value e7(json::Value("foobar")); ASSERT_TRUE(e7.is_string(), "e7 is not a string after assignment"); ASSERT_EQ(e7.as_string(), "foobar", "e7 has incorrect value after assignment"); json::Value e8(json::object()); ASSERT_TRUE(e8.is_object(), "e8 is not an object after assignment"); json::Value e9(json::null()); ASSERT_TRUE(e9.is_null(), "e9 is not null after assignment"); json::Value e10(json::array()); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); e10.set_at(0, json::Value("foobar")); ASSERT_EQ(e10.size(), 1, "e10 has incorrect number of elements after assignment"); ASSERT_EQ(e10[0].as_string(), "foobar", "e10[0] has incorrect value after assignment"); e10.set_at(1, json::Value("foobar")); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment"); ASSERT_EQ(e10[1].as_string(), "foobar", "e10[0] has incorrect value after assignment"); e10.set_at(0, json::Value("barfoo")); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment"); ASSERT_EQ(e10[0].as_string(), "barfoo", "e10[0] has incorrect value after assignment"); e10.set_at(100, json::null()); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment"); e10.insert_at(1, json::Value("new")); ASSERT_EQ(e10.size(), 3, "e10 has incorrect size after insert"); ASSERT_EQ(e10[1].as_string(), "new", "e10[1] has incorrect value after insert"); ASSERT_EQ(e10[2].as_string(), "foobar", "e10[2] has incorrect value after insert"); e10.del_at(0); ASSERT_EQ(e10.size(), 2, "e10 has incorrect size after delete"); ASSERT_EQ(e10[1].as_string(), "foobar", "e10[1] has incorrect value after delete"); e10.clear(); ASSERT_EQ(e10.size(), 0, "e10 has incorrect number of elements after clear"); json::Value e11(json::object()); ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment"); e11.set_key("foo", json::Value("test")); ASSERT_EQ(e11.size(), 1, "e11 has incorrect number of properties after assignment"); ASSERT_EQ(e11["foo"].as_string(), "test", "e11.foo has incorrect value after assignment"); e11.set_key("foo", json::Value("again")); ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment"); ASSERT_EQ(e11.size(), 1, "e11 has incorrect number of properties after assignment"); ASSERT_EQ(e11["foo"].as_string(), "again", "e11.foo has incorrect value after assignment"); e11.set_key("bar", json::Value("test")); ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment"); ASSERT_EQ(e11.size(), 2, "e11 has incorrect number of properties after assignment"); ASSERT_EQ(e11["bar"].as_string(), "test", "e11.foo has incorrect value after assignment"); e11.clear(); ASSERT_EQ(e11.size(), 0, "e11 has incorrect number of properties after clear"); json::Value e12(json::object()); e12.set_key("foo", json::Value("test")); e12.set_key("bar", json::Value(3)); char* out_cstr = e12.save_string(JSON_COMPACT); std::string out(out_cstr); free(out_cstr); ASSERT_EQ(out, "{\"bar\":3,\"foo\":\"test\"}", "object did not serialize as expected"); std::istringstream instr(out); instr >> e12; ASSERT_TRUE(e12.is_object(), "e12 is not an object after stream read"); ASSERT_EQ(e12.size(), 2, "e12 has wrong size after stream read"); ASSERT_EQ(e12.get("bar").as_integer(), 3, "e12.bar has incorrect value after stream read"); ASSERT_EQ(e12.get("foo").as_string(), "test", "ee12.test has incorrect value after stream read"); std::ostringstream outstr; outstr << e12; ASSERT_EQ(instr.str(), "{\"bar\":3,\"foo\":\"test\"}", "object did not serialize as expected"); const json::Value e13(e12); ASSERT_EQ(e13["bar"].as_integer(), 3, "e13.bar has incorrect value after copy"); json::Value e14(json::object()); ASSERT_TRUE(e14.is_object(), "e14 is not an object after construction"); e14.set_key("foo", json::object()); ASSERT_TRUE(e14["foo"].is_object(), "e14.foo is not an object after assignment"); e14["foo"]["bar"] = json::Value(42); ASSERT_EQ(e14["foo"]["bar"].as_integer(), 42, "e14.foo.bar has incorrect value after assignment"); json::Value e15(json::array()); ASSERT_TRUE(e15.is_array(), "e15 is not an array after construction"); e15.set_at(0, json::Value(42)); ASSERT_EQ(e15[0].as_integer(), 42, "e15[0] has incorrect value after assignment"); e15[0] = json::Value("foo"); ASSERT_EQ(e15[0].as_string(), "foo", "e15[0] has incorrecy value after assignment"); return 0; }