Beispiel #1
0
void TNodeJsFOut::writeJson(const v8::FunctionCallbackInfo<v8::Value>& Args) {
    v8::Isolate* Isolate = v8::Isolate::GetCurrent();
    v8::HandleScope HandleScope(Isolate);
    
    PJsonVal JsonVal = TNodeJsUtil::GetArgJson(Args, 0);
    TStr JsonStr = JsonVal->SaveStr();
    
    TNodeJsFOut* JsFOut = ObjectWrap::Unwrap<TNodeJsFOut>(Args.This());
    EAssertR(!JsFOut->SOut.Empty(), "Output stream already closed!");
    JsonStr.Save(*JsFOut->SOut);
    
    Args.GetReturnValue().Set(Args.Holder());
}
Beispiel #2
0
TEST(TStr, SaveLoad) {
	const TStr FNm = "test1.txt";

	const TStr Empty;
	const TStr Alphabet = "abcdefghijklmnoprstuvz";
	TStr Empty1, Alphabet1;

	// is big
	Empty.Save(*TFOut::New(FNm, false)(), false);
	Empty1 = Alphabet;
	Empty1.Load(*TFIn::New(FNm)(), false);
	EXPECT_EQ(Empty, Empty1);
	EXPECT_EQ(Empty, TStr(*TFIn::New(FNm)(), false));
	EXPECT_EQ(0, Empty1.Len());

	Empty.Save(*TFOut::New(FNm, false)(), false);
	Empty1 = Empty;
	Empty1.Load(*TFIn::New(FNm)(), false);
	EXPECT_EQ(Empty, Empty1);
	EXPECT_EQ(Empty, TStr(*TFIn::New(FNm)(), false));
	EXPECT_EQ(0, Empty1.Len());

	Alphabet.Save(*TFOut::New(FNm, false)(), false);
	Alphabet1 = Alphabet;
	Alphabet1.Load(*TFIn::New(FNm)(), false);
	EXPECT_EQ(Alphabet, Alphabet1);
	EXPECT_EQ(Alphabet, TStr(*TFIn::New(FNm)(), false));

	Alphabet.Save(*TFOut::New(FNm, false)(), false);
	Alphabet1 = Empty;
	Alphabet1.Load(*TFIn::New(FNm)(), false);
	EXPECT_EQ(Alphabet, Alphabet1);
	EXPECT_EQ(Alphabet, TStr(*TFIn::New(FNm)(), false));

	// is small
	Empty.Save(*TFOut::New(FNm, false)(), true);
	Empty1 = Alphabet;
	Empty1.Load(*TFIn::New(FNm)(), true);
	EXPECT_EQ(Empty, Empty1);
	EXPECT_EQ(Empty, TStr(*TFIn::New(FNm)(), true));
	EXPECT_EQ(0, Empty1.Len());

	Empty.Save(*TFOut::New(FNm, false)(), true);
	Empty1 = Empty;
	Empty1.Load(*TFIn::New(FNm)(), true);
	EXPECT_EQ(Empty, Empty1);
	EXPECT_EQ(Empty, TStr(*TFIn::New(FNm)(), true));
	EXPECT_EQ(0, Empty1.Len());

	Alphabet.Save(*TFOut::New(FNm, false)(), true);
	Alphabet1 = Alphabet;
	Alphabet1.Load(*TFIn::New(FNm)(), true);
	EXPECT_EQ(Alphabet, Alphabet1);
	EXPECT_EQ(Alphabet, TStr(*TFIn::New(FNm)(), true));

	Alphabet.Save(*TFOut::New(FNm, false)(), true);
	Alphabet1 = Empty;
	Alphabet1.Load(*TFIn::New(FNm)(), true);
	EXPECT_EQ(Alphabet, Alphabet1);
	EXPECT_EQ(Alphabet, TStr(*TFIn::New(FNm)(), true));

	// normal constructor
	{
		TFOut FOut(FNm, false);
		FOut.PutStr(Empty);
	}

	EXPECT_EQ(Empty, TStr(TFIn::New(FNm)));
	EXPECT_EQ(0, TStr(TFIn::New(FNm)).Len());

	{
		TFOut FOut(FNm, false);
		FOut.PutStr(Alphabet);
	}

	EXPECT_EQ(Alphabet, TStr(TFIn::New(FNm)));
}