summaryrefslogtreecommitdiffstats
path: root/courgette/encoded_program_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/encoded_program_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/encoded_program_unittest.cc')
-rw-r--r--courgette/encoded_program_unittest.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/courgette/encoded_program_unittest.cc b/courgette/encoded_program_unittest.cc
new file mode 100644
index 0000000..aedb838
--- /dev/null
+++ b/courgette/encoded_program_unittest.cc
@@ -0,0 +1,64 @@
+// 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 "courgette/encoded_program.h"
+
+#include "courgette/streams.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(EncodedProgramTest, Test) {
+ //
+ // Create a simple program with a few addresses and references and
+ // check that the bits produced are as expected.
+ //
+ courgette::EncodedProgram* program = new courgette::EncodedProgram();
+
+ uint32 base = 0x00900000;
+ program->set_image_base(base);
+
+ program->DefineRel32Label(5, 0); // REL32 index 5 == base + 0
+ program->DefineAbs32Label(7, 4); // ABS32 index 7 == base + 4
+ program->EndLabels();
+
+ program->AddOrigin(0); // Start at base.
+ program->AddAbs32(7);
+ program->AddRel32(5);
+
+ // Serialize and deserialize.
+
+ courgette::SinkStreamSet sinks;
+ program->WriteTo(&sinks);
+
+ courgette::SinkStream sink;
+ bool can_collect = sinks.CopyTo(&sink);
+ EXPECT_TRUE(can_collect);
+
+ const void* buffer = sink.Buffer();
+ size_t length = sink.Length();
+
+ courgette::SourceStreamSet sources;
+ bool can_get_source_streams = sources.Init(buffer, length);
+ EXPECT_TRUE(can_get_source_streams);
+
+ courgette::EncodedProgram *encoded2 = new courgette::EncodedProgram();
+ bool can_read = encoded2->ReadFrom(&sources);
+ EXPECT_TRUE(can_read);
+
+ // Finally, try to assemble.
+ courgette::SinkStream assembled;
+ bool can_assemble = encoded2->AssembleTo(&assembled);
+ EXPECT_TRUE(can_assemble);
+
+ const void* assembled_buffer = assembled.Buffer();
+ size_t assembled_length = assembled.Length();
+
+ EXPECT_EQ(8, assembled_length);
+
+ static const uint8 golden[] = {
+ 0x04, 0x00, 0x90, 0x00, // ABS32 to base + 4
+ 0xF8, 0xFF, 0xFF, 0xFF // REL32 from next line to base + 2
+ };
+
+ EXPECT_EQ(0, memcmp(assembled_buffer, golden, 8));
+}