Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: import/cross/destination_buffer_test.cc

Issue 149236: Add o3djs.DestinationBuffer to converter.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2009, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "tests/common/win/testing_common.h"
33 #include "import/cross/destination_buffer.h"
34 #include "core/cross/class_manager.h"
35 #include "core/cross/object_manager.h"
36 #include "core/cross/pack.h"
37 #include "core/cross/service_dependency.h"
38
39 namespace o3d {
40
41 class DestinationBufferTest : public testing::Test {
42 protected:
43 DestinationBufferTest()
44 : class_manager_(g_service_locator),
45 object_manager_(g_service_locator) {
46 class_manager_->AddTypedClass<DestinationBuffer>();
47 }
48
49 virtual void SetUp();
50 virtual void TearDown();
51
52 Pack* pack() { return pack_; }
53
54 private:
55 ServiceDependency<ClassManager> class_manager_;
56 ServiceDependency<ObjectManager> object_manager_;
57 Pack* pack_;
58 };
59
60 void DestinationBufferTest::SetUp() {
61 pack_ = object_manager_->CreatePack();
62 }
63
64 void DestinationBufferTest::TearDown() {
65 object_manager_->DestroyPack(pack_);
66 }
67
68
69 // Creates a Destination buffer, tests basic properties, and checks that writing
70 // then reading data works.
71 TEST_F(DestinationBufferTest, TestDestinationBuffer) {
72 Buffer *buffer = pack()->Create<DestinationBuffer>();
73 EXPECT_TRUE(buffer->IsA(DestinationBuffer::GetApparentClass()));
74 EXPECT_TRUE(buffer->IsA(VertexBuffer::GetApparentClass()));
75 EXPECT_TRUE(buffer->IsA(Buffer::GetApparentClass()));
76
77 const size_t kSize = 100;
78 Field* field = buffer->CreateField(UInt32Field::GetApparentClass(), 1);
79 ASSERT_TRUE(field != NULL);
80 ASSERT_TRUE(buffer->AllocateElements(kSize));
81 EXPECT_EQ(kSize * sizeof(uint32), buffer->GetSizeInBytes()); // NOLINT
82
83 // Put some data into the buffer.
84 uint32 *data = NULL;
85 ASSERT_TRUE(buffer->LockAs(Buffer::WRITE_ONLY, &data));
86 ASSERT_TRUE(data != NULL);
87 for (uint32 i = 0; i < kSize; ++i) {
88 data[i] = i;
89 }
90 ASSERT_TRUE(buffer->Unlock());
91
92 data = NULL;
93 // Read the data from the buffer, checks that it's the expected values.
94 ASSERT_TRUE(buffer->LockAs(Buffer::READ_ONLY, &data));
95 ASSERT_TRUE(data != NULL);
96 for (uint32 i = 0; i < kSize; ++i) {
97 EXPECT_EQ(i, data[i]);
98 }
99 ASSERT_TRUE(buffer->Unlock());
100 }
101
102
103 } // namespace o3d
104
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698