summaryrefslogtreecommitdiff
path: root/chromeos-dbus-bindings/method_name_generator_unittest.cc
blob: 040c18884ff70d5ce7f42e0e66ce34c46ab623fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos-dbus-bindings/method_name_generator.h"

#include <string>
#include <vector>

#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
#include <gtest/gtest.h>

#include "chromeos-dbus-bindings/interface.h"

using std::string;
using testing::Test;

namespace chromeos_dbus_bindings {

namespace {

const char kMethodName0[] = "Zircon";
const char kMethodName1[] = "Encrusted";
const char kMethodName2[] = "Tweezers";
const char kExpectedOutput[] = R"(
namespace MyInterface {
const char kZirconMethod[] = "Zircon";
const char kEncrustedMethod[] = "Encrusted";
const char kTweezersMethod[] = "Tweezers";
}  // namespace MyInterface
)";

}  // namespace

class MethodNameGeneratorTest : public Test {
 public:
  void SetUp() override {
    ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
  }

 protected:
  base::FilePath CreateInputFile(const string& contents) {
    base::FilePath path;
    EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &path));
    int written = base::WriteFile(path, contents.c_str(), contents.size());
    EXPECT_EQ(contents.size(), static_cast<size_t>(written));
    return path;
  }

  base::ScopedTempDir temp_dir_;
};

TEST_F(MethodNameGeneratorTest, GnerateMethodNames) {
  Interface interface;
  interface.name = "MyInterface";
  interface.methods.emplace_back(kMethodName0);
  interface.methods.emplace_back(kMethodName1);
  interface.methods.emplace_back(kMethodName2);
  base::FilePath output_path = temp_dir_.path().Append("output.h");
  EXPECT_TRUE(MethodNameGenerator::GenerateMethodNames({interface},
                                                       output_path));
  string contents;
  EXPECT_TRUE(base::ReadFileToString(output_path, &contents));
  EXPECT_STREQ(kExpectedOutput, contents.c_str());
}

}  // namespace chromeos_dbus_bindings