Fix action icons in the log dialog being clipped on High-DPI displays
[TortoiseGit.git] / test / UnitTests / FileTextLinesTest.cpp
blobd4d4dd6cdf6abcd4b7a27117e4da383cfc259065
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "FileTextLines.h"
23 TEST(CFileTextLines, CheckUnicodeType)
25 unsigned char ascii[] = "some text";
26 // This text contains the umlaut "ä".
27 unsigned char ansi[] = { 0x54, 0x68, 0x69, 0x73, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x63, 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x75, 0x6D, 0x6C, 0x61, 0x75, 0x74, 0x20, 0x22, 0xE4, 0x22, 0x2E };
28 unsigned char utf8[] = { 0x54, 0x68, 0x69, 0x73, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x63, 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x75, 0x6D, 0x6C, 0x61, 0x75, 0x74, 0x20, 0x22, 0xC3, 0xA4, 0x22, 0x2E };
29 unsigned char utf8bom[] = { 0xEF, 0xBB, 0xBF, 0x54, 0x68, 0x69, 0x73, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x63, 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x75, 0x6D, 0x6C, 0x61, 0x75, 0x74, 0x20, 0x22, 0xC3, 0xA4, 0x22, 0x2E };
30 unsigned char utf16be[] = { 0x00, 0x54, 0x00, 0x68, 0x00, 0x69, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00, 0x74, 0x00, 0x20, 0x00, 0x63, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x68, 0x00, 0x65, 0x00, 0x20, 0x00, 0x75, 0x00, 0x6D, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x75, 0x00, 0x74, 0x00, 0x20, 0x00, 0x22, 0x00, 0xE4, 0x00, 0x22, 0x00, 0x2E };
31 unsigned char utf16bebom[] = { 0xFE, 0xFF, 0x00, 0x54, 0x00, 0x68, 0x00, 0x69, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00, 0x74, 0x00, 0x20, 0x00, 0x63, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x68, 0x00, 0x65, 0x00, 0x20, 0x00, 0x75, 0x00, 0x6D, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x75, 0x00, 0x74, 0x00, 0x20, 0x00, 0x22, 0x00, 0xE4, 0x00, 0x22, 0x00, 0x2E };
32 unsigned char utf16le[] = { 0x54, 0x00, 0x68, 0x00, 0x69, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00, 0x74, 0x00, 0x20, 0x00, 0x63, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x68, 0x00, 0x65, 0x00, 0x20, 0x00, 0x75, 0x00, 0x6D, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x75, 0x00, 0x74, 0x00, 0x20, 0x00, 0x22, 0x00, 0xE4, 0x00, 0x22, 0x00, 0x2E, 0x00 };
33 unsigned char utf16lebom[] = { 0xFF, 0xFE, 0x54, 0x00, 0x68, 0x00, 0x69, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00, 0x74, 0x00, 0x20, 0x00, 0x63, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x20, 0x00, 0x74, 0x00, 0x68, 0x00, 0x65, 0x00, 0x20, 0x00, 0x75, 0x00, 0x6D, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x75, 0x00, 0x74, 0x00, 0x20, 0x00, 0x22, 0x00, 0xE4, 0x00, 0x22, 0x00, 0x2E, 0x00 };
35 CFileTextLines ftl;
36 EXPECT_EQ(CFileTextLines::ASCII, ftl.CheckUnicodeType(ascii, sizeof(ascii) - 1));
37 EXPECT_EQ(CFileTextLines::ASCII, ftl.CheckUnicodeType(ansi, sizeof(ansi)));
38 EXPECT_EQ(CFileTextLines::UTF8, ftl.CheckUnicodeType(utf8, sizeof(utf8)));
39 EXPECT_EQ(CFileTextLines::UTF8BOM, ftl.CheckUnicodeType(utf8bom, sizeof(utf8bom)));
40 EXPECT_EQ(CFileTextLines::UTF16_BE, ftl.CheckUnicodeType(utf16be, sizeof(utf16be)));
41 EXPECT_EQ(CFileTextLines::UTF16_BEBOM, ftl.CheckUnicodeType(utf16bebom, sizeof(utf16bebom)));
42 EXPECT_EQ(CFileTextLines::UTF16_LE, ftl.CheckUnicodeType(utf16le, sizeof(utf16le)));
43 EXPECT_EQ(CFileTextLines::UTF16_LEBOM, ftl.CheckUnicodeType(utf16lebom, sizeof(utf16lebom)));