Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: mojo/dart/embedder/test/validation_unittest.cc

Issue 1545483003: Dart: Reorganize files (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix build file Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/dart/embedder/test/run_dart_tests.cc ('k') | mojo/dart/http_load_test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
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 <set>
6 #include <string>
7 #include <vector>
8
9 #include "base/bind.h"
10 #include "base/files/file_enumerator.h"
11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h"
13 #include "base/logging.h"
14 #include "base/path_service.h"
15 #include "base/rand_util.h"
16 #include "base/strings/string_util.h"
17 #include "mojo/dart/embedder/dart_controller.h"
18 #include "mojo/dart/embedder/test/dart_test.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace mojo {
22 namespace dart {
23 namespace {
24
25 class DartValidationTest : public DartTest {
26 public:
27
28 DartValidationTest() {}
29
30 std::string GetPath() {
31 base::FilePath path;
32 PathService::Get(base::DIR_SOURCE_ROOT, &path);
33 path = path.AppendASCII("mojo")
34 .AppendASCII("public")
35 .AppendASCII("interfaces")
36 .AppendASCII("bindings")
37 .AppendASCII("tests")
38 .AppendASCII("data")
39 .AppendASCII("validation");
40
41 return path.AsUTF8Unsafe();
42 }
43
44 void RunTest(const std::string& test) {
45 base::FilePath path;
46 PathService::Get(base::DIR_SOURCE_ROOT, &path);
47 path = path.AppendASCII("mojo")
48 .AppendASCII("dart")
49 .AppendASCII("test")
50 .AppendASCII("validation_test.dart");
51 std::vector<std::string> script_arguments =
52 CollectTests(base::FilePath(test));
53
54 RunDartTest(path, script_arguments, false, false, 0);
55 }
56
57 private:
58 // Enumerates files inside |path| and collects all data needed to run
59 // conformance tests.
60 // For each test there are three entries in the returned vector.
61 // [0] -> test name.
62 // [1] -> contents of test's .data file.
63 // [2] -> contents of test's .expected file.
64 static std::vector<std::string> CollectTests(base::FilePath path) {
65 base::FileEnumerator enumerator(path, false, base::FileEnumerator::FILES);
66 std::set<std::string> tests;
67 while (true) {
68 base::FilePath file_path = enumerator.Next();
69 if (file_path.empty()) {
70 break;
71 }
72 file_path = file_path.RemoveExtension();
73 tests.insert(file_path.value());
74 }
75 std::vector<std::string> result;
76 for (auto it = tests.begin(); it != tests.end(); it++) {
77 const std::string& test_name = *it;
78 std::string source;
79 bool r;
80 std::string filename = base::FilePath(test_name).BaseName().value();
81 if (!StartsWithASCII(filename, "conformance_", true)) {
82 // Only include conformance tests.
83 continue;
84 }
85 base::FilePath data_path(test_name);
86 data_path = data_path.AddExtension(".data");
87 base::FilePath expected_path(test_name);
88 expected_path = expected_path.AddExtension(".expected");
89 // Test name.
90 result.push_back(test_name.c_str());
91 // Test's .data.
92 r = ReadFileToString(data_path, &source);
93 DCHECK(r);
94 result.push_back(source);
95 source.clear();
96 // Test's .expected.
97 r = ReadFileToString(expected_path, &source);
98 DCHECK(r);
99 result.push_back(source);
100 source.clear();
101 }
102 return result;
103 }
104 };
105
106 TEST_F(DartValidationTest, validation) {
107 RunTest(GetPath());
108 }
109
110 } // namespace
111 } // namespace dart
112 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/dart/embedder/test/run_dart_tests.cc ('k') | mojo/dart/http_load_test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698