TEST(WideToUtf8, OverlappingParametersFits)
{
	int32_t errors = UTF8_ERR_NONE;

	uint8_t data[128] = { 0 };
	data[0 * sizeof(wchar_t)] = 'o';
	data[1 * sizeof(wchar_t)] = 'f';
	data[2 * sizeof(wchar_t)] = 'f';
	data[3 * sizeof(wchar_t)] = 's';
	data[4 * sizeof(wchar_t)] = 'e';
	data[5 * sizeof(wchar_t)] = 't';

	const wchar_t* i = (const wchar_t*)data;
	size_t is = 6 * sizeof(wchar_t);
	char* o = (char*)(data + is);
	size_t os = 6;

	EXPECT_EQ(6, widetoutf8(i, is, o, os, &errors));
#if UTF8_WCHAR_UTF32
	EXPECT_MEMEQ("o\0\0\0f\0\0\0f\0\0\0s\0\0\0e\0\0\0t\0\0\0offset", (const char*)data, 30);
#else
	EXPECT_MEMEQ("o\0f\0f\0s\0e\0t\0offset", (const char*)data, 18);
#endif
	EXPECT_ERROREQ(UTF8_ERR_NONE, errors);
}
コード例 #2
0
TEST(LineReader, MultiLineFile) {
  SystemMock sys;
  static const char kFile[] =
      "This is a multi\n"
      "line text file that to test the crazy::LineReader class implementation\n"
      "And this is a very long text line to check that the class properly "
      "handles them, through the help of dynamic allocation or something. "
      "Yadda yadda yadda yadda. No newline";
  static const size_t kFileSize = sizeof(kFile) - 1;
  sys.AddRegularFile(kFilePath, kFile, kFileSize);

  LineReader reader(kFilePath);

  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_MEMEQ("This is a multi\n", 16, reader.line(), reader.length());

  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_MEMEQ(
      "line text file that to test the crazy::LineReader class "
      "implementation\n",
      88 - 17,
      reader.line(),
      reader.length());

  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_MEMEQ(
      "And this is a very long text line to check that the class properly "
      "handles them, through the help of dynamic allocation or something. "
      "Yadda yadda yadda yadda. No newline\n",
      187 - 17,
      reader.line(),
      reader.length());

  EXPECT_FALSE(reader.GetNextLine());
}
コード例 #3
0
TEST(LineReader, SingleLineFile) {
  SystemMock sys;
  static const char kFile[] = "foo bar\n";
  static const size_t kFileSize = sizeof(kFile) - 1;
  sys.AddRegularFile(kFilePath, kFile, kFileSize);

  LineReader reader(kFilePath);
  EXPECT_TRUE(reader.GetNextLine());
  EXPECT_EQ(kFileSize, reader.length());
  EXPECT_MEMEQ(kFile, kFileSize, reader.line(), reader.length());
  EXPECT_FALSE(reader.GetNextLine());
}
コード例 #4
0
TEST(LineReader, SingleLineFileUnterminated) {
  SystemMock sys;
  static const char kFile[] = "foo bar";
  static const size_t kFileSize = sizeof(kFile) - 1;
  sys.AddRegularFile(kFilePath, kFile, kFileSize);

  LineReader reader(kFilePath);
  EXPECT_TRUE(reader.GetNextLine());
  // The LineReader will add a newline to the last line.
  EXPECT_EQ(kFileSize + 1, reader.length());
  EXPECT_MEMEQ(kFile, kFileSize, reader.line(), reader.length() - 1);
  EXPECT_EQ('\n', reader.line()[reader.length() - 1]);
  EXPECT_FALSE(reader.GetNextLine());
}