TEST_F(AggregateSQLTests, EmptyTableTest) { PL_ASSERT(&TestingSQLUtil::counter_); PL_ASSERT(&TestingSQLUtil::traffic_cop_); auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); auto txn = txn_manager.BeginTransaction(); catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn); txn_manager.CommitTransaction(txn); // Create a table first TestingSQLUtil::ExecuteSQLQuery( "CREATE TABLE xxx(a INT PRIMARY KEY, b INT);"); LOG_DEBUG("execute one query"); std::vector<ResultValue> result; std::vector<FieldInfo> tuple_descriptor; std::string error_message; int rows_affected; // optimizer::Optimizer optimizer; // All of these aggregates should return null std::vector<std::string> nullAggregates = {"MIN", "MAX", "AVG", "SUM"}; std::vector<type::TypeId> expectedTypes = { type::TypeId::INTEGER, type::TypeId::INTEGER, type::TypeId::DECIMAL, type::TypeId::INTEGER}; for (int i = 0; i < (int)nullAggregates.size(); i++) { std::string expected; std::ostringstream os; os << "SELECT " << nullAggregates[i] << "(b) FROM xxx"; TestingSQLUtil::ExecuteSQLQuery(os.str(), result, tuple_descriptor, rows_affected, error_message); std::string resultStr(result[0].begin(), result[0].end()); EXPECT_EQ(expected, resultStr); } // These aggregates should return zero std::vector<std::string> zeroAggregates = {"COUNT"}; for (int i = 0; i < (int)zeroAggregates.size(); i++) { std::string expected = type::ValueFactory::GetIntegerValue(0).ToString(); std::ostringstream os; os << "SELECT " << zeroAggregates[i] << "(b) FROM xxx"; TestingSQLUtil::ExecuteSQLQuery(os.str(), result, tuple_descriptor, rows_affected, error_message); std::string resultStr(result[0].begin(), result[0].end()); EXPECT_EQ(expected, resultStr); } }
TEST_F(AggregateSQLTests, EmptyTableTest) { catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, nullptr); // Create a table first SQLTestsUtil::ExecuteSQLQuery("CREATE TABLE xxx(a INT PRIMARY KEY, b INT);"); std::vector<ResultType> result; std::vector<FieldInfoType> tuple_descriptor; std::string error_message; int rows_affected; optimizer::SimpleOptimizer optimizer; // All of these aggregates should return null std::vector<std::string> nullAggregates = {"MIN", "MAX", "AVG", "SUM"}; std::vector<type::Type::TypeId> expectedTypes = { type::Type::INTEGER, type::Type::INTEGER, type::Type::DECIMAL, type::Type::INTEGER}; for (int i = 0; i < (int)nullAggregates.size(); i++) { std::string expected; std::ostringstream os; os << "SELECT " << nullAggregates[i] << "(b) FROM xxx"; SQLTestsUtil::ExecuteSQLQuery(os.str(), result, tuple_descriptor, rows_affected, error_message); std::string resultStr(result[0].second.begin(), result[0].second.end()); EXPECT_EQ(expected, resultStr); } // These aggregates should return zero std::vector<std::string> zeroAggregates = {"COUNT"}; for (int i = 0; i < (int)zeroAggregates.size(); i++) { std::string expected = type::ValueFactory::GetIntegerValue(0).ToString(); std::ostringstream os; os << "SELECT " << zeroAggregates[i] << "(b) FROM xxx"; SQLTestsUtil::ExecuteSQLQuery(os.str(), result, tuple_descriptor, rows_affected, error_message); std::string resultStr(result[0].second.begin(), result[0].second.end()); EXPECT_EQ(expected, resultStr); } }
//--------------------------------------------------------------------- String Skill::getShakeTimeString(void) const { String resultStr(""); for (size_t i=0; i<mShakeTimeArray.size(); ++i) { resultStr += Ogre::StringConverter::toString(mShakeTimeArray[i]); resultStr += " "; } return resultStr; }
// This test is a regression test for a fixed bug in the copy constructor. // It is kept as a global function rather than as a method since the test depends on memory values. // (At least before the bug was fixed, whether it showed up or not depended on memory contents, // which is probably why it didn't show up in the regular test for the copy constructor.) // For this reason, the test isn't changed even though it contains function calls whose results are // not tested and had no problems. Actually, the test failed by *crashing*. static void _testCopyConstructor2() { UErrorCode status = U_ZERO_ERROR; UnicodeString formatStr("Hello World on {0,date,full}", ""); UnicodeString resultStr(" ", ""); UnicodeString result; FieldPosition fp(0); UDate d = Calendar::getNow(); const Formattable fargs( d, Formattable::kIsDate ); MessageFormat* fmt1 = new MessageFormat( formatStr, status ); MessageFormat* fmt2 = new MessageFormat( *fmt1 ); MessageFormat* fmt3; MessageFormat* fmt4; if (fmt1 == NULL) it_err("testCopyConstructor2: (fmt1 != NULL)"); result = fmt1->format( &fargs, 1, resultStr, fp, status ); if (fmt2 == NULL) it_err("testCopyConstructor2: (fmt2 != NULL)"); fmt3 = (MessageFormat*) fmt1->clone(); fmt4 = (MessageFormat*) fmt2->clone(); if (fmt3 == NULL) it_err("testCopyConstructor2: (fmt3 != NULL)"); if (fmt4 == NULL) it_err("testCopyConstructor2: (fmt4 != NULL)"); result = fmt1->format( &fargs, 1, resultStr, fp, status ); result = fmt2->format( &fargs, 1, resultStr, fp, status ); result = fmt3->format( &fargs, 1, resultStr, fp, status ); result = fmt4->format( &fargs, 1, resultStr, fp, status ); delete fmt1; delete fmt2; delete fmt3; delete fmt4; }
std::string RESTRepDataItem::getDataAsStr() { std::string resultStr( (const char *)bufferPtr, dataLength ); return resultStr; }