[M108 Migration][HBBTV] Implement ewk_context_register_jsplugin_mime_types API
[platform/framework/web/chromium-efl.git] / courgette / program_detector_unittest.cc
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "courgette/program_detector.h"
6
7 #include <string>
8
9 #include "courgette/base_test_unittest.h"
10 #include "courgette/courgette.h"
11 #include "courgette/disassembler.h"
12 #include "courgette/disassembler_elf_32_x86.h"
13 #include "courgette/disassembler_win32_x64.h"
14 #include "courgette/disassembler_win32_x86.h"
15
16 namespace courgette {
17
18 namespace {
19
20 class ProgramDetectorTest : public BaseTest {
21  public:
22   void TestQuickDetect(const std::string& test_data,
23                        ExecutableType expected_type) const;
24   void TestDetectDisassembler(const std::string& test_data,
25                               ExecutableType expected_type) const;
26 };
27
28 void ProgramDetectorTest::TestQuickDetect(const std::string& test_data,
29                                           ExecutableType expected_type) const {
30   // QuickDetect() should return true only for the |expected_type|.
31   EXPECT_EQ(expected_type == EXE_WIN_32_X86,
32             DisassemblerWin32X86::QuickDetect(
33                 reinterpret_cast<const uint8_t*>(test_data.data()),
34                 test_data.size()));
35   EXPECT_EQ(expected_type == EXE_WIN_32_X64,
36             DisassemblerWin32X64::QuickDetect(
37                 reinterpret_cast<const uint8_t*>(test_data.data()),
38                 test_data.size()));
39   EXPECT_EQ(expected_type == EXE_ELF_32_X86,
40             DisassemblerElf32X86::QuickDetect(
41                 reinterpret_cast<const uint8_t*>(test_data.data()),
42                 test_data.size()));
43 }
44
45 void ProgramDetectorTest::TestDetectDisassembler(
46     const std::string& test_data,
47     ExecutableType expected_type) const {
48   ExecutableType detected_type = EXE_UNKNOWN;
49   size_t detected_length = 0;
50   DetectExecutableType(reinterpret_cast<const uint8_t*>(test_data.data()),
51                        test_data.size(), &detected_type, &detected_length);
52   EXPECT_EQ(expected_type, detected_type);
53   EXPECT_EQ(test_data.size(), detected_length);
54 }
55
56 TEST_F(ProgramDetectorTest, All) {
57   std::string win32_x86 = FileContents("setup1.exe");
58   std::string win32_x64 = FileContents("chrome64_1.exe");
59   std::string elf_32 = FileContents("elf-32-1");
60
61   TestQuickDetect(win32_x86, EXE_WIN_32_X86);
62   TestQuickDetect(win32_x64, EXE_WIN_32_X64);
63   TestQuickDetect(elf_32, EXE_ELF_32_X86);
64
65   TestDetectDisassembler(win32_x86, EXE_WIN_32_X86);
66   TestDetectDisassembler(win32_x64, EXE_WIN_32_X64);
67   TestDetectDisassembler(elf_32, EXE_ELF_32_X86);
68 }
69
70 }  // namespace
71
72 }  // namespace courgette