1fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Copyright 2008, Google Inc.
2fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// All rights reserved.
3fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
4fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Redistribution and use in source and binary forms, with or without
5fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// modification, are permitted provided that the following conditions are
6fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// met:
7fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
8fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     * Redistributions of source code must retain the above copyright
9fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// notice, this list of conditions and the following disclaimer.
10fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     * Redistributions in binary form must reproduce the above
11fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// copyright notice, this list of conditions and the following disclaimer
12fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// in the documentation and/or other materials provided with the
13fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// distribution.
14fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//     * Neither the name of Google Inc. nor the names of its
15fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// contributors may be used to endorse or promote products derived from
16fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// this software without specific prior written permission.
17fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
18fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
300ddac1f3791efefb2cffdb425f0c600feb7a47e6Jeff Davidson// Author: preston.a.jackson@gmail.com (Preston Jackson)
31fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
32fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Google Test - FrameworkSample
33fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// widget_test.cc
34fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//
35fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
36fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This is a simple test file for the Widget class in the Widget.framework
37fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
38fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <string>
39fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <gtest/gtest.h>
40fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
41fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville#include <Widget/widget.h>
42fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
43fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This test verifies that the constructor sets the internal state of the
44fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Widget class correctly.
45fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleTEST(WidgetInitializerTest, TestConstructor) {
46fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  Widget widget(1.0f, "name");
47fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  EXPECT_FLOAT_EQ(1.0f, widget.GetFloatValue());
48fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  EXPECT_EQ(std::string("name"), widget.GetStringValue());
49fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville}
50fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
51fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// This test verifies the conversion of the float and string values to int and
52fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// char*, respectively.
53fbaaef999ba563838ebd00874ed8a1c01fbf286dWink SavilleTEST(WidgetInitializerTest, TestConversion) {
54fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  Widget widget(1.0f, "name");
55fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  EXPECT_EQ(1, widget.GetIntValue());
56fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
57fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  size_t max_size = 128;
58fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  char buffer[max_size];
59fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  widget.GetCharPtrValue(buffer, max_size);
60fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  EXPECT_STREQ("name", buffer);
610ddac1f3791efefb2cffdb425f0c600feb7a47e6Jeff Davidson}
62fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
63fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Use the Google Test main that is linked into the framework. It does something
64fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// like this:
65fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// int main(int argc, char** argv) {
66fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   testing::InitGoogleTest(&argc, argv);
67fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville//   return RUN_ALL_TESTS();
68fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// }
69