Exemplo n.º 1
0
void WorkspaceSerializer::Read(const QString& fileName, SignalData& data, PlotInfo& plotInfo)
{
	DataMap newData;
	::Read(fileName, data, plotInfo, [&](Signal&& signal){
		auto signalName = signal.name;
		newData.emplace(std::move(signalName), std::move(signal));
	}, [&]{
		data.add(std::move(newData));
	});
}
void WorkspaceSerializerTests::WriteTest()
{
	DataMap dataMap = {
		{ "cubic", 
			{
				"cubic", { 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000 }, { "#008000", true, 1, 1000 }
			} 
		},
		{ "line",
			{
				"line", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, { "#ffff00", false, 1, 10 }
			}
		}
	};
	PlotInfo plot;
	plot.setBackgroundColor("red");
	SignalData data;
	data.add(dataMap);
	data.setAsDomain("line");

	QString tmpFileName = std::tmpnam(nullptr);
	struct guard
	{
		guard(const QString& fileName)
			: fileName(fileName)
		{
		}
		~guard()
		{
			QFile f(fileName);
			f.remove();
		}
		const QString& fileName;
	} fileDeleter(tmpFileName);

	WorkspaceSerializer::Write(tmpFileName, data, plot);
	
	VerifyActualDataAndPersistedFile(tmpFileName, dataMap, "line", "red");
}