📄 datetime.cpp
字号:
CIMDateTime topA0(tot_num0, true); if (top_cdt0 != topA0) { PEGASUS_TEST_ASSERT(false); } CIMDateTime top_cdt2("00040520041412.1234**+000"); CIMDateTime topA_cdt2("00000520041452.******:000"); Uint64 top_num2 = top_cdt2.toMicroSeconds(); Uint64 topA_num2 = topA_cdt2.toMicroSeconds(); Uint64 tot_num2 = top_num2 + topA_num2; top_cdt2 += topA_cdt2; CIMDateTime topA2(tot_num2, false); if (top_cdt2 != topA2) { PEGASUS_TEST_ASSERT(false); } CIMDateTime top_cdt3("00020220******.******+230"); CIMDateTime topA_cdt3("00000220041452.******:000"); Uint64 top_num3 = top_cdt3.toMicroSeconds(); Uint64 topA_num3 = topA_cdt3.toMicroSeconds(); Uint64 tot_num3 = top_num3 + topA_num3; top_cdt3 += topA_cdt3; Uint64 top_3n = top_cdt3.toMicroSeconds(); CIMDateTime tA(tot_num3, false); if (tA != top_cdt3) { PEGASUS_TEST_ASSERT(false); } CIMDateTime top_cdt4("00040520041412.123435+000"); CIMDateTime topA_cdt4("00000520041452.123456:000"); Uint64 top_num4 = top_cdt4.toMicroSeconds(); Uint64 topA_num4 = topA_cdt4.toMicroSeconds(); Uint64 tot_num4 = top_num4 + topA_num4; CIMDateTime tot_cdt4(tot_num4, false); // tot_cdt4 = tot_cdt4.setUctOffSet(-100); top_cdt4 += topA_cdt4; if (String::compare(top_cdt4.toString(), tot_cdt4.toString())) { PEGASUS_TEST_ASSERT(false); } /*************************************************************************************************/ // "testing the operator- Uint64 tfo_m = PEGASUS_UINT64_LITERAL(123456732445); Uint64 tfo_mA = PEGASUS_UINT64_LITERAL(6789143423); CIMDateTime tfo_mCDT(tfo_m, true); CIMDateTime tfo_mACDT(tfo_mA, true); Uint64 sum_m = tfo_m - tfo_mA; CIMDateTime dif_CDT(sum_m, true); CIMDateTime CDT_dif = tfo_mCDT - tfo_mACDT; if (String::compare(dif_CDT.toString(), CDT_dif.toString())) { PEGASUS_TEST_ASSERT(false); } Uint64 tfo_m2 = PEGASUS_UINT64_LITERAL(12357647324458); Uint64 tfo_mA2 = PEGASUS_UINT64_LITERAL(6789143423); CIMDateTime tfo_mCDT2(tfo_m2, false); CIMDateTime tfo_mACDT2(tfo_mA2, true); Uint64 dif_m2 = tfo_m2 - tfo_mA2; CIMDateTime dif_CDT2(dif_m2, false); CIMDateTime CDT_dif2 = tfo_mCDT2 - tfo_mACDT2; if (String::compare(dif_CDT2.toString(), CDT_dif2.toString())) { PEGASUS_TEST_ASSERT(false); } Uint64 tfo_m3 = PEGASUS_UINT64_LITERAL(12357647324458); Uint64 tfo_mA3 = PEGASUS_UINT64_LITERAL(6789143423); CIMDateTime tfo_mCDT3(tfo_m3, false); CIMDateTime tfo_mACDT3(tfo_mA3, false); Uint64 dif_m3 = tfo_m3 - tfo_mA3; CIMDateTime dif_CDT3(dif_m3, true); CIMDateTime CDT_dif3 = tfo_mCDT3 - tfo_mACDT3; if (String::compare(dif_CDT3.toString(), CDT_dif3.toString())) { PEGASUS_TEST_ASSERT(false); } Uint64 tfo_m4 = PEGASUS_UINT64_LITERAL(123576473244426265); Uint64 tfo_mA4 = PEGASUS_UINT64_LITERAL(6789143423435); CIMDateTime mCDT4(tfo_m4, false); CIMDateTime tfo_mACDT4(tfo_mA4, false); Uint64 dif_m4 = tfo_m4 - tfo_mA4; CIMDateTime CDT_dif4 = mCDT4 - tfo_mACDT4; Uint64 CDT_num = CDT_dif4.toMicroSeconds(); if (CDT_num != dif_m4) { PEGASUS_TEST_ASSERT(false); } /************************************************************************************************/ // testing operator-= CIMDateTime top_tko4("00040520041412.123435-000"); CIMDateTime topA_tko4("00000520041452.123456:000"); Uint64 top_yup4 = top_tko4.toMicroSeconds(); Uint64 topA_yup4 = topA_tko4.toMicroSeconds(); Uint64 ot_yup4 = top_yup4 - topA_yup4; top_tko4 -= topA_tko4; CIMDateTime tko4(ot_yup4, false); if (top_tko4 != tko4) { PEGASUS_TEST_ASSERT(false); } CIMDateTime top_tko2("00040520041412.123435:000"); CIMDateTime topA_tko2("00000520041452.123456:000"); Uint64 top_yup2 = top_tko2.toMicroSeconds(); Uint64 topA_yup2 = topA_tko2.toMicroSeconds(); Uint64 ot_yup2 = top_yup2 - topA_yup2; top_tko2 -= topA_tko2; Uint64 tko2 = top_tko2.toMicroSeconds(); if (ot_yup2 != tko2) { PEGASUS_TEST_ASSERT(false); } CIMDateTime top_tko3("00040520041412.123435+000"); CIMDateTime topA_tko3("00000520041452.123***:000"); Uint64 top_yup3 = top_tko3.toMicroSeconds(); Uint64 topA_yup3 = topA_tko3.toMicroSeconds(); Uint64 ot_yup3 = top_yup3 - topA_yup3; top_tko3 -= topA_tko3; CIMDateTime tko3(ot_yup3, false); if (top_tko3 != tko3) { PEGASUS_TEST_ASSERT(false); } /*******************************************************************************************///test operator* CIMDateTime mul1("00000020041452.123456:000"); Uint64 m_num1 = 12; CIMDateTime pr_c1 = mul1 * m_num1; Uint64 mul_cn1 = mul1.toMicroSeconds() * m_num1; CIMDateTime c_pr1(mul_cn1, true); if (String::compare(c_pr1.toString(), pr_c1.toString())) { PEGASUS_TEST_ASSERT(false); } CIMDateTime mul2("00000020041452.12****:000"); Uint64 m_num2 = 2; CIMDateTime pr_c2 = mul2 * m_num2; Uint64 mul_cn2 = mul2.toMicroSeconds() * m_num2; Uint64 pr_num2 = pr_c2.toMicroSeconds(); if (pr_num2 != mul_cn2) { PEGASUS_TEST_ASSERT(false); } CIMDateTime mul3("000123200414**.******:000"); Uint64 m_num3 = 2; CIMDateTime pr_c3 = mul3 * m_num3; Uint64 mul_cn3 = mul3.toMicroSeconds() * m_num2; Uint64 pr_num3 = pr_c3.toMicroSeconds(); if (pr_num3 != mul_cn3) { PEGASUS_TEST_ASSERT(false); } /*************************************************************************************/ // test operator*= CIMDateTime ul1("00000020041452.123456:000"); m_num1 = 12; Uint64 ul_cn1 = ul1.toMicroSeconds() * m_num1; ul1 *= m_num1; Uint64 ul_num1 = ul1.toMicroSeconds(); if (ul_num1 != ul_cn1) { PEGASUS_TEST_ASSERT(false); } CIMDateTime ul2("00000020041452.123***:000"); m_num2 = 12; Uint64 ul_cn2 = ul2.toMicroSeconds() * m_num2; ul2 *= m_num2; Uint64 ul_num2 = ul2.toMicroSeconds(); if (ul_num2 != ul_cn2) { PEGASUS_TEST_ASSERT(false); }/*********************************************************************************************/ // testing operator CIMDateTime dul1("00000020041452.123456:000"); Uint64 d_num1 = 12; CIMDateTime r_c1 = dul1 / d_num1; Uint64 dul_cn1 = dul1.toMicroSeconds() / d_num1; Uint64 r_num1 = r_c1.toMicroSeconds(); if (r_num1 != dul_cn1) { PEGASUS_TEST_ASSERT(false); } CIMDateTime dul2("00023020041452.12****:000"); Uint64 d_num2 = 12; CIMDateTime r_c2 = dul2 / d_num2; Uint64 dul_cn2 = dul2.toMicroSeconds() / d_num2; CIMDateTime dulc(dul_cn2, true); Uint64 r_num2 = r_c2.toMicroSeconds(); if (dulc != r_c2) { PEGASUS_TEST_ASSERT(false); }/*****************************************************************************************/ // testing operator/= d_num1 = 50; CIMDateTime dull1("00000520041452.123456:000"); Uint64 dull_cn1 = dull1.toMicroSeconds() / d_num1; dull1 /= d_num1; Uint64 dul_num1 = dull1.toMicroSeconds(); if (dul_num1 != dull_cn1) { PEGASUS_TEST_ASSERT(false); }/*********************************************************************************************/ // "testing I/I operator/ " CIMDateTime tii1("00040520041412.123435:000"); CIMDateTime tii_a1("00000520041452.123456:000"); Uint64 tii_n1 = tii1.toMicroSeconds(); Uint64 tii_an1 = tii_a1.toMicroSeconds(); Uint64 div_n = tii_n1 / tii_an1; Uint64 div_c = tii1 / tii_a1; if (div_n != div_c) { PEGASUS_TEST_ASSERT(false); } CIMDateTime tii2("000405200414**.******:000"); CIMDateTime tii_a2("00000520041452.1234**:000"); Uint64 tii_n2 = tii2.toMicroSeconds(); Uint64 tii_an2 = tii_a2.toMicroSeconds(); Uint64 div_n2 = tii_n2 / tii_an2; Uint64 div_c2 = tii2 / tii_a2; if (div_n != div_c) { PEGASUS_TEST_ASSERT(false); } /****************************************************************************************/ // testing of comparison CIMDateTime las("000405200414**.******:000"); CIMDateTime last("00040520041435.74****:000"); if (las > last) { PEGASUS_TEST_ASSERT(false); } if (las < last) { PEGASUS_TEST_ASSERT(false); } if (!(las >= last)) { PEGASUS_TEST_ASSERT(false); } if (!(las <= last)) { PEGASUS_TEST_ASSERT(false); } if (las != last) { PEGASUS_TEST_ASSERT(false); } CIMDateTime las2("000405200414**.******+000"); CIMDateTime last2("00040520041435.74****+000"); if (las2 > last2) { PEGASUS_TEST_ASSERT(false); } if (las2 < last2) { PEGASUS_TEST_ASSERT(false); } if (!(las2 >= last2)) { PEGASUS_TEST_ASSERT(false); } if (!(las2 <= last2)) { PEGASUS_TEST_ASSERT(false); } if (las2 != last2) { PEGASUS_TEST_ASSERT(false); } CIMDateTime las3("0004052004****.******+050"); CIMDateTime last3("00040520041435.74****+000"); if (las3 > last3) { PEGASUS_TEST_ASSERT(false); } if (las3 < last3) { PEGASUS_TEST_ASSERT(false); } if (!(las3 >= last3)) { PEGASUS_TEST_ASSERT(false); } if (!(las3 <= last3)) { PEGASUS_TEST_ASSERT(false); } if (las3 != last3) { PEGASUS_TEST_ASSERT(false); } CIMDateTime las4("000405200444**.******+030"); CIMDateTime last4("00040520041435.74****+000"); if (las4 > last4) { PEGASUS_TEST_ASSERT(false); } if (las4 < last4) { PEGASUS_TEST_ASSERT(false); } if (!(las4 >= last4)) { PEGASUS_TEST_ASSERT(false); } if (!(las4 <= last4)) { PEGASUS_TEST_ASSERT(false); } if (las4 != last4) { PEGASUS_TEST_ASSERT(false); } } catch(Exception & e) { cout << "Exception: " << e.getMessage() << endl; cout << "Exception caught at the end of test file" << endl; exit(1); } { // 20040811165625.000000+000 CIMDateTime x(PEGASUS_UINT64_LITERAL(63259462585000000), false); CIMDateTime y("20060908113026.000000-300"); PEGASUS_TEST_ASSERT(y > x); } cout << argv[0] << " +++++ passed all tests" << endl; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -