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 : // Declares utilities for building unittests dealing with BlockGraphs.
16 :
17 : #ifndef SYZYGY_BLOCK_GRAPH_UNITTEST_UTIL_H_
18 : #define SYZYGY_BLOCK_GRAPH_UNITTEST_UTIL_H_
19 :
20 : #include "syzygy/block_graph/block_graph.h"
21 : #include "syzygy/block_graph/block_graph_serializer.h"
22 : #include "syzygy/block_graph/transform_policy.h"
23 :
24 : namespace testing {
25 :
26 : // TODO(chrisha): Once we transition fully to BlockGraphSerializer, remove
27 : // the redundant comparison functions.
28 :
29 : // Compares two Blocks (from different BlockGraphs) to each other. Intended for
30 : // testing BlockGraph serialization.
31 : bool BlocksEqual(const block_graph::BlockGraph::Block& b1,
32 : const block_graph::BlockGraph::Block& b2,
33 : const block_graph::BlockGraphSerializer& bgs);
34 :
35 : // Compares two BlockGraphs to each other. Intended for testing BlockGraph
36 : // serialization.
37 : bool BlockGraphsEqual(
38 : const block_graph::BlockGraph& b1,
39 : const block_graph::BlockGraph& b2,
40 : const block_graph::BlockGraphSerializer& bgs);
41 :
42 : // Generate a block-graph to use in the tests.
43 : bool GenerateTestBlockGraph(block_graph::BlockGraph* image);
44 :
45 : // A dummy transform policy object for unittesting.
46 : class DummyTransformPolicy : public block_graph::TransformPolicyInterface {
47 : public:
48 E : DummyTransformPolicy() { }
49 E : virtual ~DummyTransformPolicy() { }
50 :
51 : // @name TransformPolicyInterface implementation
52 : // @{
53 : virtual bool BlockIsSafeToBasicBlockDecompose(
54 : const BlockGraph::Block* block) const override;
55 : virtual bool ReferenceIsSafeToRedirect(
56 : const BlockGraph::Block* referrer,
57 : const BlockGraph::Reference& reference) const override;
58 : // @}
59 :
60 : private:
61 : DISALLOW_COPY_AND_ASSIGN(DummyTransformPolicy);
62 : };
63 :
64 : } // namespace testing
65 :
66 : #endif // SYZYGY_BLOCK_GRAPH_UNITTEST_UTIL_H_
|