summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-15 22:06:00 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-15 22:06:00 +0000
commit567dae2f920dbc1bdaf6d9defda0253b833f305b (patch)
treecc4e1b99eb5050d908d1703d07e93e302ed9f22c /remoting
parente9f4968f7ba8d56a36894c48287e51bed6e95f4a (diff)
downloadchromium_src-567dae2f920dbc1bdaf6d9defda0253b833f305b.zip
chromium_src-567dae2f920dbc1bdaf6d9defda0253b833f305b.tar.gz
chromium_src-567dae2f920dbc1bdaf6d9defda0253b833f305b.tar.bz2
Chromoting unit test: Adding DecoderVerbatimTest
Adding a test case to DecodeVerbatimTest. TEST=remoting_unittests Review URL: http://codereview.chromium.org/2849006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/client/decoder_verbatim.cc6
-rw-r--r--remoting/client/decoder_verbatim_unittest.cc53
-rw-r--r--remoting/client/mock_objects.h28
-rw-r--r--remoting/remoting.gyp1
4 files changed, 83 insertions, 5 deletions
diff --git a/remoting/client/decoder_verbatim.cc b/remoting/client/decoder_verbatim.cc
index 6d0f976..69b04ae 100644
--- a/remoting/client/decoder_verbatim.cc
+++ b/remoting/client/decoder_verbatim.cc
@@ -22,8 +22,8 @@ bool DecoderVerbatim::BeginDecode(scoped_refptr<media::VideoFrame> frame,
decode_done_.reset(decode_done);
updated_rects_ = updated_rects;
- // TODO(hclam): Check if we can accept the color format of the video frame and
- // the codec.
+ // TODO(hclam): Check if we can accept the color format of the video frame
+ // and the codec.
frame_ = frame;
return true;
}
@@ -46,7 +46,7 @@ bool DecoderVerbatim::PartialDecode(HostMessage* message) {
bytes_per_pixel = 2;
} else if (pixel_format == PixelFormatRgb32) {
bytes_per_pixel = 4;
- } else if (pixel_format != PixelFormatAscii) {
+ } else if (pixel_format == PixelFormatAscii) {
bytes_per_pixel = 1;
} else {
NOTREACHED() << "Pixel format not supported";
diff --git a/remoting/client/decoder_verbatim_unittest.cc b/remoting/client/decoder_verbatim_unittest.cc
index b9c1d79..d450cb7 100644
--- a/remoting/client/decoder_verbatim_unittest.cc
+++ b/remoting/client/decoder_verbatim_unittest.cc
@@ -2,12 +2,61 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "media/base/video_frame.h"
+#include "remoting/client/decoder_verbatim.h"
+#include "remoting/client/mock_objects.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using ::testing::InSequence;
+
namespace remoting {
-// TODO(hclam): Implement unit tests.
-TEST(DecoderVerbatimTest, Simple) {
+TEST(DecoderVerbatimTest, SimpleDecode) {
+ DecoderVerbatim decoder;
+ scoped_refptr<MockDecodeDoneHandler> handler = new MockDecodeDoneHandler();
+
+ const size_t kWidth = 10;
+ const size_t kHeight = 1;
+ const char kData[] = "ABCDEFGHIJ";
+ scoped_ptr<HostMessage> msg(new HostMessage());
+ msg->mutable_update_stream_packet()->mutable_header()->set_width(kWidth);
+ msg->mutable_update_stream_packet()->mutable_header()->set_height(kHeight);
+ msg->mutable_update_stream_packet()->mutable_header()->set_x(0);
+ msg->mutable_update_stream_packet()->mutable_header()->set_y(0);
+ msg->mutable_update_stream_packet()->mutable_header()->set_pixel_format(
+ PixelFormatAscii);
+ msg->mutable_update_stream_packet()->set_data(kData, sizeof(kData));
+
+ scoped_refptr<media::VideoFrame> frame;
+ media::VideoFrame::CreateFrame(media::VideoFrame::ASCII, kWidth, kHeight,
+ base::TimeDelta(), base::TimeDelta(), &frame);
+ ASSERT_TRUE(frame);
+
+ InSequence s;
+ EXPECT_CALL(*handler, PartialDecodeDone());
+ EXPECT_CALL(*handler, DecodeDone());
+
+ UpdatedRects rects;
+ decoder.BeginDecode(
+ frame, &rects,
+ NewRunnableMethod(handler.get(),
+ &MockDecodeDoneHandler::PartialDecodeDone),
+ NewRunnableMethod(handler.get(), &MockDecodeDoneHandler::DecodeDone));
+ decoder.PartialDecode(msg.release());
+ decoder.EndDecode();
+
+ // Make sure we get the same data back.
+ EXPECT_EQ(kWidth, frame->width());
+ EXPECT_EQ(kHeight, frame->height());
+ EXPECT_EQ(media::VideoFrame::ASCII, frame->format());
+ EXPECT_EQ(0, memcmp(kData, frame->data(media::VideoFrame::kRGBPlane),
+ sizeof(kData)));
+
+ // Check the updated rects.
+ ASSERT_TRUE(rects.size() == 1);
+ EXPECT_EQ(kWidth, static_cast<size_t>(rects[0].width()));
+ EXPECT_EQ(kHeight, static_cast<size_t>(rects[0].height()));
}
} // namespace remoting
diff --git a/remoting/client/mock_objects.h b/remoting/client/mock_objects.h
new file mode 100644
index 0000000..06ed801
--- /dev/null
+++ b/remoting/client/mock_objects.h
@@ -0,0 +1,28 @@
+// Copyright (c) 2010 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.
+
+#ifndef REMOTING_CLIENT_MOCK_OBJECTS_H_
+#define REMOTING_CLIENT_MOCK_OBJECTS_H_
+
+#include "base/ref_counted.h"
+#include "remoting/client/decoder.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace remoting {
+
+class MockDecodeDoneHandler :
+ public base::RefCountedThreadSafe<MockDecodeDoneHandler> {
+ public:
+ MockDecodeDoneHandler() {}
+
+ MOCK_METHOD0(PartialDecodeDone, void());
+ MOCK_METHOD0(DecodeDone, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockDecodeDoneHandler);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CLIENT_MOCK_OBJECTS_H_
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 0f203a8..f62a83e 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -331,6 +331,7 @@
'base/mock_objects.h',
'base/multiple_array_input_stream_unittest.cc',
'base/protocol_decoder_unittest.cc',
+ 'client/mock_objects.h',
'client/decoder_verbatim_unittest.cc',
'host/differ_unittest.cc',
'host/differ_block_unittest.cc',