summaryrefslogtreecommitdiffstats
path: root/courgette/adjustment_method_unittest.cc
diff options
context:
space:
mode:
authorsra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 23:00:29 +0000
committersra@chromium.org <sra@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 23:00:29 +0000
commit04ca1bc65afb76ea30698c25f24599d20119e3d2 (patch)
tree2bb65e974d478f4d607b83f6a84a56c01f501ac0 /courgette/adjustment_method_unittest.cc
parent9adf1dcf3281408560267787eddcc767566b425f (diff)
downloadchromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.zip
chromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.tar.gz
chromium_src-04ca1bc65afb76ea30698c25f24599d20119e3d2.tar.bz2
Move Courgette
from src\third_party\courgette to src\courgette and src\courgette\third_party Fixed #includes Added properties to ignore generated files: C:\c5\src>svn pg svn:ignore courgette courgette.xcodeproj courgette.sln courgette_fuzz.vcproj courgette_lib.vcproj courgette_minimal_tool.vcproj courgette_tool.vcproj courgette.vcproj courgette_unittests.vcproj SConstruct courgette_fuzz.scons courgette_lib.scons courgette_main.scons courgette_minimal_tool.scons courgette.scons courgette_tool.scons courgette_unittests.scons Review URL: http://codereview.chromium.org/115062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/adjustment_method_unittest.cc')
-rw-r--r--courgette/adjustment_method_unittest.cc108
1 files changed, 108 insertions, 0 deletions
diff --git a/courgette/adjustment_method_unittest.cc b/courgette/adjustment_method_unittest.cc
new file mode 100644
index 0000000..661b23d
--- /dev/null
+++ b/courgette/adjustment_method_unittest.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/path_service.h"
+#include "base/file_util.h"
+#include "base/string_util.h"
+
+#include "courgette/assembly_program.h"
+#include "courgette/courgette.h"
+#include "courgette/streams.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+class AdjustmentMethodTest : public testing::Test {
+ public:
+ void Test1() const;
+
+ private:
+ void SetUp() {
+ }
+
+ void TearDown() {
+ }
+
+ // Returns one of two similar a simple programs. They differ only in the
+ // label assignment, so that it is possible to make them look identical.
+ courgette::AssemblyProgram* MakeProgram(int kind) const {
+ courgette::AssemblyProgram* prog = new courgette::AssemblyProgram();
+ prog->set_image_base(0x00400000);
+
+ courgette::Label* labelA = prog->FindOrMakeAbs32Label(0x00410000);
+ courgette::Label* labelB = prog->FindOrMakeAbs32Label(0x00410004);
+
+ prog->EmitAbs32(labelA);
+ prog->EmitAbs32(labelA);
+ prog->EmitAbs32(labelB);
+ prog->EmitAbs32(labelA);
+ prog->EmitAbs32(labelA);
+ prog->EmitAbs32(labelB);
+
+ if (kind == 0) {
+ labelA->index_ = 0;
+ labelB->index_ = 1;
+ } else {
+ labelA->index_ = 1;
+ labelB->index_ = 0;
+ }
+ prog->AssignRemainingIndexes();
+
+ return prog;
+ }
+
+ courgette::AssemblyProgram* MakeProgramA() const { return MakeProgram(0); }
+ courgette::AssemblyProgram* MakeProgramB() const { return MakeProgram(1); }
+
+ // Returns a string that is the serialized version of |program|.
+ // Deletes |program|.
+ std::string Serialize(courgette::AssemblyProgram *program) const {
+ courgette::EncodedProgram* encoded = NULL;
+
+ const courgette::Status encode_status = Encode(program, &encoded);
+ EXPECT_EQ(courgette::C_OK, encode_status);
+
+ DeleteAssemblyProgram(program);
+
+ courgette::SinkStreamSet sinks;
+ const courgette::Status write_status = WriteEncodedProgram(encoded, &sinks);
+ EXPECT_EQ(courgette::C_OK, write_status);
+
+ DeleteEncodedProgram(encoded);
+
+ courgette::SinkStream sink;
+ bool can_collect = sinks.CopyTo(&sink);
+ EXPECT_TRUE(can_collect);
+
+ return std::string(reinterpret_cast<const char *>(sink.Buffer()),
+ sink.Length());
+ }
+};
+
+
+void AdjustmentMethodTest::Test1() const {
+ courgette::AssemblyProgram* prog1 = MakeProgramA();
+ courgette::AssemblyProgram* prog2 = MakeProgramB();
+ std::string s1 = Serialize(prog1);
+ std::string s2 = Serialize(prog2);
+
+ // Don't use EXPECT_EQ because strings are unprintable.
+ EXPECT_FALSE(s1 == s2); // Unadjusted A and B differ.
+
+ courgette::AssemblyProgram* prog5 = MakeProgramA();
+ courgette::AssemblyProgram* prog6 = MakeProgramB();
+ courgette::Status can_adjust = Adjust(*prog5, prog6);
+ EXPECT_EQ(courgette::C_OK, can_adjust);
+ std::string s5 = Serialize(prog5);
+ std::string s6 = Serialize(prog6);
+
+ EXPECT_TRUE(s1 == s5); // Adjustment did not change A (prog5)
+ EXPECT_TRUE(s5 == s6); // Adjustment did change B into A
+}
+
+
+TEST_F(AdjustmentMethodTest, All) {
+ Test1();
+}