TEST (json, fetch_object) { std::string string1 ("{ \"thing\": \"junktest\" }"); std::stringstream stream1 (string1); json_upgrade_test object1; auto error1 (rai::fetch_object (object1, stream1)); ASSERT_FALSE (error1); ASSERT_EQ ("changed", object1.text); boost::property_tree::ptree tree1; stream1.seekg (0); boost::property_tree::read_json (stream1, tree1); ASSERT_EQ ("changed", tree1.get <std::string> ("thing")); std::string string2 ("{ \"thing\": \"junktest2\" }"); std::stringstream stream2 (string2); json_upgrade_test object2; auto error2 (rai::fetch_object (object2, stream2)); ASSERT_FALSE (error2); ASSERT_EQ ("junktest2", object2.text); ASSERT_EQ ("{ \"thing\": \"junktest2\" }", string2); std::string string3 ("{ \"thing\": \"error\" }"); std::stringstream stream3 (string3); json_upgrade_test object3; auto error3 (rai::fetch_object (object3, stream3)); ASSERT_TRUE (error3); std::fstream stream4; rai::open_or_create (stream4, rai::unique_path().string()); json_upgrade_test object4; auto error4 (rai::fetch_object (object4, stream4)); ASSERT_FALSE (error4); ASSERT_EQ ("created", object4.text); boost::property_tree::ptree tree2; stream4.seekg (0); boost::property_tree::read_json (stream4, tree2); ASSERT_EQ ("created", tree2.get <std::string> ("thing")); }
TestRefcountedString() { { // copy construct SmartString string1("string1"); SmartString string2(string1); SmartString string3(string2); } { // refcounted assignment SmartString string1("string1"); SmartString string2("string2"); string1 = string2; } { // copy assignment SmartString string1("string1"); SmartString string2("string2"); string1 = string2.c_str(); } { // self-assignment SmartString string1("string1"); string1 = string1; } { // self-assignment via another reference SmartString string1("string1"); SmartString string2(string1); string1 = string2; } }
TEST_F(SecureStringTests, DISABLED_testConstructors) { OpenAB::SecureString string("test"); OpenAB::SecureString string1(string); OpenAB::SecureString string2 = string; OpenAB::SecureString string3(std::string("test")); ASSERT_TRUE(strcmp("test", string.str()) == 0); ASSERT_TRUE(strcmp("test", string1.str()) == 0); ASSERT_TRUE(strcmp("test", string2.str()) == 0); ASSERT_TRUE(strcmp("test", string3.str()) == 0); string.clearStr(); string.clear(); ASSERT_TRUE(strcmp("test", string.str()) == 1); }
TEST(fxcrt, ByteStringCNotNull) { CFX_ByteStringC string3("abc"); CFX_ByteStringC string6("abcdef"); CFX_ByteStringC alternate_string3("abcdef", 3); CFX_ByteStringC embedded_nul_string7("abc\0def", 7); CFX_ByteStringC illegal_string7("abcdef", 7); EXPECT_EQ(3, string3.GetLength()); EXPECT_EQ(6, string6.GetLength()); EXPECT_EQ(3, alternate_string3.GetLength()); EXPECT_EQ(7, embedded_nul_string7.GetLength()); EXPECT_EQ(7, illegal_string7.GetLength()); EXPECT_NE(string3, string6); EXPECT_EQ(string3, alternate_string3); EXPECT_NE(string3, embedded_nul_string7); EXPECT_NE(string3, illegal_string7); EXPECT_NE(string6, alternate_string3); EXPECT_NE(string6, embedded_nul_string7); EXPECT_NE(string6, illegal_string7); EXPECT_NE(alternate_string3, embedded_nul_string7); EXPECT_NE(alternate_string3, illegal_string7); EXPECT_NE(embedded_nul_string7, illegal_string7); CFX_ByteStringC copied_string3(string3); CFX_ByteStringC copied_alternate_string3(alternate_string3); CFX_ByteStringC copied_embedded_nul_string7(embedded_nul_string7); EXPECT_EQ(string3, copied_string3); EXPECT_EQ(alternate_string3, copied_alternate_string3); EXPECT_EQ(embedded_nul_string7, copied_embedded_nul_string7); CFX_ByteStringC assigned_string3("intially something else"); CFX_ByteStringC assigned_alternate_string3("initally something else"); CFX_ByteStringC assigned_ptr_string3("initially something else"); CFX_ByteStringC assigned_embedded_nul_string7("initially something else"); assigned_string3 = string3; assigned_alternate_string3 = alternate_string3; assigned_ptr_string3 = "abc"; assigned_embedded_nul_string7 = embedded_nul_string7; EXPECT_EQ(string3, assigned_string3); EXPECT_EQ(alternate_string3, assigned_alternate_string3); EXPECT_EQ(alternate_string3, assigned_ptr_string3); EXPECT_EQ(embedded_nul_string7, assigned_embedded_nul_string7); }
void TestChainTraverserComments::TestStringHighlightStyles() { ComparisonContext cContext; CRTF_String string(&cContext, Detached); assertTest(string.GetHighlightStyle()==DV_STYLE_INSERTION); string.DeleteAll(); assertTest(string.GetHighlightStyle()==DV_STYLE_DELETION); CRTF_String string2(&cContext, Detached); string2.MarkMatched(); assertTest(string2.GetHighlightStyle()==DV_STYLE_MATCH); CRTF_String string3(&cContext, Detached); string3.SetAsDVPComment(); assertTest(string3.GetHighlightStyle()==DV_STYLE_INSERTEDCOMMENT); // COMMENT_STUFF string3.DeleteAll(); assertTest(string3.GetHighlightStyle()==DV_STYLE_DELETEDCOMMENT); // COMMENT_STUFF }
int main(int argc, const char* argv[]) { std::string string1("Testing the comparision functions."); std::string string2("Hello"); std::string string3("stinger"); std::string string4(string2); std::cout << "string1: " << string1 << "\nstring2: " << string2 << "\nstring3: " << string3 << "\nstring4: " << string4 << "\n\n"; // comparing string1 and string4 if (string1 == string4) std::cout << "string1 == string4\n"; else { if (string1 > string4) std::cout << "string1 > string4\n"; else std::cout << "string1 < string4\n"; } // comparing string1 and string2 int result = string1.compare(string2); if (result == 0) std::cout << "string1.compare(string2) == 0\n"; else { if (result > 0) std::cout << "string1.compare(string2) > 0\n"; else std::cout << "string1.compare(string2) < 0\n"; } // comparing string1 (elements 2-5) and string3 (elements 0-5) result = string1.compare(2, 5, string3, 0, 5); if (result == 0) std::cout << "string1.compare(2, 5, string3, 0, 5) == 0\n"; else { if (result > 0) std::cout << "string1.compare(2, 5, string3, 0, 5) > 0\n"; else std::cout << "string1.compare(2, 5, string3, 0, 5) < 0\n"; } // comparing string2 and string4 result = string4.compare(0, string2.length(), string2); if (result == 0) std::cout << "string4.compare(0, string2.length(), string2) == 0" << std::endl; else { if (result > 0) std::cout << "string4.compare(0, string2.length(), string2) > 0" << std::endl; else std::cout << "string4.compare(0, string2.length(), string2) < 0" << std::endl; } // comparing string2 and string4 result = string2.compare(0, 3, string4); if (result == 0) std::cout << "string2.compare(0, 3, string4) == 0" << std::endl; else { if (result > 0) std::cout << "string2.compare(0, 3, string4) > 0" << std::endl; else std::cout << "string2.compare(0, 3, string4) < 0" << std::endl; } return 0; }
void Debuger::DrawEntitiesStats(int eco){ sf::View currentView = _window->getView(); sf::Vector2f centerView = currentView.getCenter(); sf::Vector2f sizeView = currentView.getSize(); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); std::stringstream buffer; Scene* s = Scene::getScene(); Ecosystem *e1 = s->getEcosystem(eco); buffer << "Ecosystem " << eco << " (" << e1->getInterval().x << " - " << e1->getInterval().y <<") Num Mobs: " << e1->getMobPopulationAndTreshold().x << "/" << e1->getMobPopulationAndTreshold().y << "/" << e1->getMobPopulationAndTreshold().z << "Num Trees: " << e1->getTreePopulationAndTreshold().x << "/" << e1->getTreePopulationAndTreshold().y << "/" << e1->getTreePopulationAndTreshold().z; std::string string(buffer.str()); sf::String str(string); _text.setString(str); _window->draw(_text); _displace = _displace + DISPLACEMENT; sf::Vector2f position = _window->mapPixelToCoords(sf::Mouse::getPosition(*_window)); float zoom = s->getZoom(); sf::Vector2f position_center = sf::Vector2f(s->getPlayer()->GetPosition().x+Player::PLAYER_WIDTH/2,s->getPlayer()->GetPosition().y+Player::PLAYER_WIDTH/2); sf::Vector2f position_zoomed = (position-position_center)/zoom +position_center; position = position_zoomed; std::vector<Mob*> mobs; s->getMobsOnArea(mobs,sf::Vector2i(position),100,eco); for(int i =0; i<mobs.size();i++){ mobs[i]->_focusDebug = true; } if(mobs.size()>0) { std::stringstream buffer2; buffer2 << "Mob Position colision: " << mobs[0]->_positionCol.x << " " << mobs[0]->_positionCol.y << " Size colision: " << mobs[0]->_sizeCol.x << " " << mobs[0]->_sizeCol.y << " Radius: " << mobs[0]->getGenetics()->_distanceMaxReproduce << "/" << mobs[0]->getGenetics()->_distanceMaxMove; std::string string(buffer2.str()); sf::String str(string); _text.setString(str); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT; std::stringstream buffer3; buffer3 << "Race: " << mobs[0]->getGenetics()->_race << " Life: " << mobs[0]->_life << "/" << mobs[0]->getGenetics()->_health << " Hunger: " << mobs[0]->_hunger << "/" << mobs[0]->getGenetics()->_foodNeeds << " Age: " << mobs[0]->_age << "/" << mobs[0]->getGenetics()->_age << " Target: " << (mobs[0]->_target !=nullptr); std::string string3(buffer3.str()); sf::String str3(string3); _text.setString(str3); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT; std::stringstream buffer4; buffer4 << "Food: "; for(int i =0; i< mobs[0]->getGenetics()->_food.size();i++){ buffer4 << mobs[0]->getGenetics()->_food[i] << " "; } buffer4 << "\n Enemys: "; for(int i =0; i< mobs[0]->getGenetics()->_enemys.size();i++){ buffer4 << mobs[0]->getGenetics()->_enemys[i] << " "; } buffer4 << "\n Friends: "; for(int i =0; i< mobs[0]->getGenetics()->_friends.size();i++){ buffer4 << mobs[0]->getGenetics()->_friends[i] << " "; } buffer4 << "\n Neutral: "; for(int i =0; i< mobs[0]->getGenetics()->_neutral.size();i++){ buffer4 << mobs[0]->getGenetics()->_neutral[i] << " "; } std::string string4(buffer4.str()); sf::String str4(string4); _text.setString(str4); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT*4; } else { std::vector<Tree*> trees; s->getTreesOnArea(trees,sf::Vector2i(position),100,eco); if(trees.size() >0){ int pos_l = 0; int pos_r = 0; if(trees[0]->_left_n != nullptr) pos_l = trees[0]->_left_n->_position.x; if(trees[0]->_right_n != nullptr) pos_r = trees[0]->_right_n->_position.x; std::stringstream buffer2; buffer2 << "Tree Position: " << trees[0]->_position.x << " " << trees[0]->_position.y << " padding: " << trees[0]->_min_x << ", " << trees[0]->_max_x <<" Health: " << trees[0]->_life <<" Reproduce countdown: " << trees[0]->_timeToReproduce << "\n"; buffer2 << "Damage time: " << trees[0]->_debug_last_damage_time << " Damage distance: " << trees[0]->_debug_last_damage_distance << " Damage temp: " << trees[0]->_debug_last_damage_temp << " Damage humid " << trees[0]->_debug_last_damage_hum << "\n"; buffer2 << "Tree Fathers: " << pos_l << " " << pos_r << "\n"; TreeGenetics *gens = trees[0]->getGenetics(); buffer2 << "Tree corb: " << gens->_corb << " Tree amplitude: " << gens->_amplitude << " Tree height: " << gens->_height << "\n"; buffer2 << "Branch amount: " << gens->_branchAmount << " Curve branch: " << gens->_curveBranch << " Branch size: " << gens->_sizeBranch << "\n"; buffer2 << "Type leave: " << gens->_typeLeave << " Amount leave: " << gens->_amountLeave << " Density leave: " << gens->_densityLeave << "\n"; buffer2 << "Life: " << gens->_health << " Cold res " << gens->_cold << " Hot res " << gens->_hot << " Humidity res " << gens->_humidity << " Gen strenght " << gens->_strenghtGen << " Reproduce freq " << gens->_reproduceFactor; std::string string(buffer2.str()); sf::String str(string); _text.setString(str); _text.setPosition(centerView.x-sizeView.x/2, centerView.y-sizeView.y/2+_displace); _window->draw(_text); _displace = _displace + DISPLACEMENT*7; } } }