コード例 #1
0
ファイル: User.cpp プロジェクト: Thalhammer/EasyCpp
				void User::fromAnyValue(const AnyValue & state)
				{
					PublicUser::fromAnyValue(state);
					Bundle bundle = state.as<Bundle>();
					_birthday = bundle.isSet("birthdate") ? bundle.get<std::string>("birthdate") : "";
					_country = bundle.get<std::string>("country");
					_email = bundle.isSet("email") ? bundle.get<std::string>("email") : "";
					if (bundle.isSet("product"))
						_product = bundle.get<std::string>("product") == "premium" ? ProductType::PREMIUM : ProductType::FREE;
				}
コード例 #2
0
	TEST(PHPSessionSerializer, Deserialize)
	{
		std::string sessiondata = "bool|b:0;string|s:5:\"Hallo\";classobject|O:8:\"stdClass\":1:{s:8:\"property\";s:5:\"value\";}array|a:1:{i:0;s:5:\"hallo\";}null|N;integer|i:1;double|d:10;";
		Bundle res = Serialize::PHPSessionSerializer().deserialize(sessiondata).as<Bundle>();
		ASSERT_TRUE(res.isSet("bool"));
		ASSERT_TRUE(res.isSet("string"));
		ASSERT_TRUE(res.isSet("classobject"));
		ASSERT_TRUE(res.isSet("array"));
		ASSERT_TRUE(res.isSet("null"));
		ASSERT_TRUE(res.isSet("integer"));
		ASSERT_TRUE(res.isSet("double"));

		ASSERT_TRUE(res["bool"].isType<bool>());
		ASSERT_TRUE(res["string"].isType<std::string>());
		ASSERT_TRUE(res["classobject"].isType<Bundle>());
		ASSERT_TRUE(res["array"].isType<Bundle>());
		ASSERT_TRUE(res["null"].isType<nullptr_t>());
		ASSERT_TRUE(res["integer"].isType<int64_t>());
		ASSERT_TRUE(res["double"].isType<double>());

		ASSERT_EQ(false, res["bool"].as<bool>());
		ASSERT_EQ("Hallo", res["string"].as<std::string>());
		ASSERT_EQ(1, res["integer"].as<int64_t>());
		ASSERT_EQ(10, res["double"].as<double>());
		{
			auto c = res["classobject"].as<Bundle>();
			ASSERT_TRUE(c.isSet("property"));
			ASSERT_TRUE(c["property"].isType<std::string>());
			ASSERT_EQ("value", c["property"].as<std::string>());
		}
		{
			auto c = res["array"].as<Bundle>();
			ASSERT_TRUE(c.isSet("0"));
			ASSERT_TRUE(c["0"].isType<std::string>());
			ASSERT_EQ("hallo", c["0"].as<std::string>());
		}
	}