1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/grinder/lcov_writer.h"
16 :
17 : #include "base/files/file_util.h"
18 : #include "gmock/gmock.h"
19 : #include "gtest/gtest.h"
20 : #include "syzygy/core/unittest_util.h"
21 :
22 : namespace grinder {
23 :
24 : namespace {
25 :
26 : class TestCoverageData : public CoverageData {
27 : public:
28 E : void InitDummyData() {
29 : CoverageData::SourceFileCoverageDataMap::iterator source_it =
30 : source_file_coverage_data_map_.insert(
31 : std::make_pair(std::string("foo.cc"),
32 E : CoverageData::SourceFileCoverageData())).first;
33 :
34 : source_it->second.line_execution_count_map.insert(
35 E : std::make_pair(1, 1));
36 : source_it->second.line_execution_count_map.insert(
37 E : std::make_pair(2, 1));
38 : source_it->second.line_execution_count_map.insert(
39 E : std::make_pair(3, 0));
40 E : }
41 : };
42 :
43 : } // namespace
44 :
45 E : TEST(LcovWriterTest, Write) {
46 E : TestCoverageData coverage_data;
47 E : ASSERT_NO_FATAL_FAILURE(coverage_data.InitDummyData());
48 :
49 E : testing::ScopedTempFile temp;
50 E : EXPECT_TRUE(WriteLcovCoverageFile(coverage_data, temp.path()) );
51 :
52 E : std::string actual_contents;
53 E : EXPECT_TRUE(base::ReadFileToString(temp.path(), &actual_contents));
54 :
55 : std::string expected_contents =
56 : "SF:foo.cc\n"
57 : "DA:1,1\n"
58 : "DA:2,1\n"
59 : "DA:3,0\n"
60 : "LH:2\n"
61 : "LF:3\n"
62 E : "end_of_record\n";
63 :
64 E : EXPECT_EQ(expected_contents, actual_contents);
65 E : }
66 :
67 : } // namespace grinder
|