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

Side by Side Diff: experimental/c_salt/npapi/variant_converter_test.cc

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 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
« no previous file with comments | « experimental/c_salt/npapi/variant_converter.cc ('k') | experimental/c_salt/opengl_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 The Ginsu Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4 #include "c_salt/npapi/variant_converter.h"
5
6 #include <nacl/npruntime.h>
7
8 #include <limits>
9 #include <string>
10 #include <vector>
11
12 #include "c_salt/instance.h"
13 #include "c_salt/module.h"
14 #include "gtest/gtest.h"
15
16 namespace {
17
18 // An overload for streaming a vector of streamable types.
19 template <class T>
20 std::ostream& operator<<(std::ostream& s, const std::vector<T>& vector) {
21 typename std::vector<T>::const_iterator iter(vector.begin()),
22 last(vector.end()-1);
23 for (; iter != last; ++iter) {
24 s << *iter << ", ";
25 }
26 s << *iter << "\n";
27 return s;
28 }
29
30 class NPVariantConverterTest : public ::testing::Test {
31 protected:
32 virtual void SetUp() {}
33 };
34
35 // Create a c_salt::Variant with the given value. Convert it to NPVariant and
36 // back to make sure the result matches.
37 template <class T>
38 void CheckConversion(T value) {
39 c_salt::SharedVariant c_salt_var(new c_salt::Variant(value));
40 NPVariant np_var;
41 c_salt::SharedVariant dest_c_salt_var;
42 c_salt::npapi::VariantConverter converter(NULL);
43 converter.ConvertVariantToNPVariant(*c_salt_var, &np_var);
44 dest_c_salt_var = converter.CreateVariantFromNPVariant(np_var);
45 EXPECT_EQ(c_salt_var->variant_type(), dest_c_salt_var->variant_type());
46 EXPECT_EQ(c_salt_var->GetValue<T>(),
47 dest_c_salt_var->GetValue<T>());
48 }
49
50 TEST_F(NPVariantConverterTest, SameType) {
51 // strings
52 CheckConversion(std::string(""));
53 CheckConversion(std::string("Hello World!"));
54 CheckConversion(std::string("3.14"));
55 CheckConversion(std::string("42"));
56
57 // int32_t
58 CheckConversion(static_cast<int32_t>(-1));
59 CheckConversion(static_cast<int32_t>(0));
60 CheckConversion(static_cast<int32_t>(1));
61 CheckConversion(static_cast<int32_t>(42));
62 CheckConversion(std::numeric_limits<int32_t>::max());
63 CheckConversion(std::numeric_limits<int32_t>::min());
64
65 // double
66 CheckConversion(static_cast<double>(0));
67 CheckConversion(3.1415);
68 CheckConversion(std::numeric_limits<double>::max());
69 CheckConversion(std::numeric_limits<double>::min());
70 CheckConversion(std::numeric_limits<double>::infinity());
71
72 // bool
73 CheckConversion(true);
74 CheckConversion(false);
75 }
76
77 } // unnamed namespace
78
79 class MyInstance : public c_salt::Instance {
80 public:
81 explicit MyInstance(const NPP& instance) : c_salt::Instance(instance) {}
82 };
83
84 class TestModule : public c_salt::Module {
85 public:
86 virtual c_salt::Instance* CreateInstance(const NPP& instance) {
87 return new MyInstance(instance);
88 }
89 };
OLDNEW
« no previous file with comments | « experimental/c_salt/npapi/variant_converter.cc ('k') | experimental/c_salt/opengl_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698