forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segbits_file_reader_test.cc
93 lines (72 loc) · 2.64 KB
/
segbits_file_reader_test.cc
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
*
* Copyright (C) 2017-2020 The Project X-Ray Authors.
*
* Use of this source code is governed by a ISC-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/ISC
*
* SPDX-License-Identifier: ISC
*/
#include <prjxray/segbits_file_reader.h>
#include <map>
#include <string>
#include <gtest/gtest.h>
TEST(SegbitsFileReaderTest, NonExistantFileReturnsNull) {
EXPECT_FALSE(
prjxray::SegbitsFileReader::InitWithFile("does_not_exist"));
}
TEST(SegbitsFileReaderTest, ZeroLengthFileYieldsNoItems) {
auto segbits_reader =
prjxray::SegbitsFileReader::InitWithFile("empty_file");
ASSERT_TRUE(segbits_reader);
EXPECT_EQ(segbits_reader->begin(), segbits_reader->end());
}
TEST(SegbitsFileReaderTest, FileWithOneEntry) {
auto segbits_reader =
prjxray::SegbitsFileReader::InitWithFile("one_entry.segbits");
ASSERT_TRUE(segbits_reader);
auto begin_iter = segbits_reader->begin();
EXPECT_EQ(begin_iter->tag(), "CLBLL_L.SLICEL_X0.A5FF.ZINI");
EXPECT_EQ(begin_iter->bit(), "31_06");
EXPECT_EQ(++begin_iter, segbits_reader->end());
}
TEST(SegbitsFileReaderTest, FileWithOneEntryWithEmptyTag) {
auto segbits_reader = prjxray::SegbitsFileReader::InitWithFile(
"one_entry_empty_tag.segbits");
ASSERT_TRUE(segbits_reader);
auto begin_iter = segbits_reader->begin();
EXPECT_EQ(begin_iter->tag(), "");
EXPECT_EQ(begin_iter->bit(), "31_06");
EXPECT_EQ(++begin_iter, segbits_reader->end());
}
TEST(SegbitsFileReaderTest, FileWithOneEntryMissingBit) {
auto segbits_reader = prjxray::SegbitsFileReader::InitWithFile(
"one_entry_missing_bit.segbits");
ASSERT_TRUE(segbits_reader);
auto begin_iter = segbits_reader->begin();
EXPECT_EQ(begin_iter->tag(), "CLBLL_L.SLICEL_X0.A5FF.ZINI");
EXPECT_EQ(begin_iter->bit(), "");
EXPECT_EQ(++begin_iter, segbits_reader->end());
}
TEST(SegbitsFileReaderTest, FileWithOneEntryWithExtraWhitespace) {
auto segbits_reader = prjxray::SegbitsFileReader::InitWithFile(
"one_entry_extra_whitespace.segbits");
ASSERT_TRUE(segbits_reader);
auto begin_iter = segbits_reader->begin();
EXPECT_EQ(begin_iter->tag(), "CLBLL_L.SLICEL_X0.A5FF.ZINI");
EXPECT_EQ(begin_iter->bit(), "31_06");
EXPECT_EQ(++begin_iter, segbits_reader->end());
}
TEST(SegbitsFileReaderTest, FileWithTwoEntries) {
auto segbits_reader =
prjxray::SegbitsFileReader::InitWithFile("two_entries.segbits");
ASSERT_TRUE(segbits_reader);
auto iter = segbits_reader->begin();
EXPECT_EQ(iter->tag(), "CLBLL_L.SLICEL_X0.A5FF.ZINI");
EXPECT_EQ(iter->bit(), "31_06");
++iter;
EXPECT_EQ(iter->tag(), "CLBLL_L.SLICEL_X0.AFF.ZINI");
EXPECT_EQ(iter->bit(), "31_03");
EXPECT_EQ(++iter, segbits_reader->end());
}