Added tests for SEA IR intermediate representation.

Change-Id: Ibc55fc3d1f6f753381a9d508d250944c2c45531d
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 4d1e18d..ac3b821 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -62,7 +62,8 @@
 TEST_COMMON_SRC_FILES += \
 	compiler/utils/scoped_hashtable_test.cc \
 	compiler/sea_ir/types/type_data_test.cc \
-	compiler/sea_ir/types/type_inference_visitor_test.cc
+	compiler/sea_ir/types/type_inference_visitor_test.cc \
+	compiler/sea_ir/ir/regions_test.cc
 endif
 
 TEST_TARGET_SRC_FILES := \
diff --git a/compiler/sea_ir/ir/regions_test.cc b/compiler/sea_ir/ir/regions_test.cc
new file mode 100644
index 0000000..9813465
--- /dev/null
+++ b/compiler/sea_ir/ir/regions_test.cc
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common_test.h"
+#include "sea_ir/ir/sea.h"
+
+using utils::ScopedHashtable;
+
+namespace sea_ir {
+
+class RegionsTest : public art::CommonTest {
+};
+
+TEST_F(RegionsTest, Basics) {
+  sea_ir::SeaGraph sg(*java_lang_dex_file_);
+  sea_ir::Region* root = sg.GetNewRegion();
+  sea_ir::Region* then_region = sg.GetNewRegion();
+  sea_ir::Region* else_region = sg.GetNewRegion();
+  std::vector<sea_ir::Region*>* regions = sg.GetRegions();
+  // Test that regions have been registered correctly as children of the graph.
+  EXPECT_TRUE(std::find(regions->begin(), regions->end(), root) != regions->end());
+  EXPECT_TRUE(std::find(regions->begin(), regions->end(), then_region) != regions->end());
+  EXPECT_TRUE(std::find(regions->begin(), regions->end(), else_region) != regions->end());
+  // Check that an edge recorded correctly in both the head and the tail.
+  sg.AddEdge(root, then_region);
+  std::vector<sea_ir::Region*>* succs = root->GetSuccessors();
+  EXPECT_EQ(1U, succs->size());
+  EXPECT_EQ(then_region, succs->at(0));
+  std::vector<sea_ir::Region*>* preds = then_region->GetPredecessors();
+  EXPECT_EQ(1U, preds->size());
+  EXPECT_EQ(root, preds->at(0));
+  // Check that two edges are recorded properly for both head and tail.
+  sg.AddEdge(root, else_region);
+  succs = root->GetSuccessors();
+  EXPECT_EQ(2U, succs->size());
+  EXPECT_TRUE(std::find(succs->begin(), succs->end(), then_region) != succs->end());
+  EXPECT_TRUE(std::find(succs->begin(), succs->end(), else_region) != succs->end());
+  preds = then_region->GetPredecessors();
+  EXPECT_EQ(1U, preds->size());
+  EXPECT_EQ(root, preds->at(0));
+  preds = else_region->GetPredecessors();
+  EXPECT_EQ(1U, preds->size());
+  EXPECT_EQ(root, preds->at(0));
+}
+
+}  // namespace art
diff --git a/compiler/sea_ir/ir/sea.h b/compiler/sea_ir/ir/sea.h
index 7746a60..0b20ed7 100644
--- a/compiler/sea_ir/ir/sea.h
+++ b/compiler/sea_ir/ir/sea.h
@@ -21,11 +21,12 @@
 #include <set>
 #include <map>
 
+#include "utils/scoped_hashtable.h"
+#include "gtest/gtest_prod.h"
 #include "dex_file.h"
 #include "dex_instruction.h"
 #include "sea_ir/ir/instruction_tools.h"
 #include "sea_ir/ir/instruction_nodes.h"
-#include "utils/scoped_hashtable.h"
 
 namespace sea_ir {
 
@@ -289,8 +290,12 @@
   uint32_t method_idx_;
   uint32_t method_access_flags_;
 
- private:
+ protected:
   explicit SeaGraph(const art::DexFile& df);
+  virtual ~SeaGraph() { }
+
+ private:
+  FRIEND_TEST(RegionsTest, Basics);
   // Registers @childReg as a region belonging to the SeaGraph instance.
   void AddRegion(Region* childReg);
   // Returns new region and registers it with the  SeaGraph instance.
@@ -330,10 +335,6 @@
   // Identifies the definitions corresponding to uses for region @node
   // by using the scoped hashtable of names @ scoped_table.
   void RenameAsSSA(Region* node, utils::ScopedHashtable<int, InstructionNode*>* scoped_table);
-
-
-
-  virtual ~SeaGraph() {}
   // Generate LLVM IR for the method.
   // Precondition: ConvertToSSA().
   void GenerateLLVM();