11b362b15af34006e6a11974088a46d42b903418eJohann// Copyright 2008, Google Inc.
21b362b15af34006e6a11974088a46d42b903418eJohann// All rights reserved.
31b362b15af34006e6a11974088a46d42b903418eJohann//
41b362b15af34006e6a11974088a46d42b903418eJohann// Redistribution and use in source and binary forms, with or without
51b362b15af34006e6a11974088a46d42b903418eJohann// modification, are permitted provided that the following conditions are
61b362b15af34006e6a11974088a46d42b903418eJohann// met:
71b362b15af34006e6a11974088a46d42b903418eJohann//
81b362b15af34006e6a11974088a46d42b903418eJohann//     * Redistributions of source code must retain the above copyright
91b362b15af34006e6a11974088a46d42b903418eJohann// notice, this list of conditions and the following disclaimer.
101b362b15af34006e6a11974088a46d42b903418eJohann//     * Redistributions in binary form must reproduce the above
111b362b15af34006e6a11974088a46d42b903418eJohann// copyright notice, this list of conditions and the following disclaimer
121b362b15af34006e6a11974088a46d42b903418eJohann// in the documentation and/or other materials provided with the
131b362b15af34006e6a11974088a46d42b903418eJohann// distribution.
141b362b15af34006e6a11974088a46d42b903418eJohann//     * Neither the name of Google Inc. nor the names of its
151b362b15af34006e6a11974088a46d42b903418eJohann// contributors may be used to endorse or promote products derived from
161b362b15af34006e6a11974088a46d42b903418eJohann// this software without specific prior written permission.
171b362b15af34006e6a11974088a46d42b903418eJohann//
181b362b15af34006e6a11974088a46d42b903418eJohann// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
191b362b15af34006e6a11974088a46d42b903418eJohann// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
201b362b15af34006e6a11974088a46d42b903418eJohann// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
211b362b15af34006e6a11974088a46d42b903418eJohann// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
221b362b15af34006e6a11974088a46d42b903418eJohann// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231b362b15af34006e6a11974088a46d42b903418eJohann// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
241b362b15af34006e6a11974088a46d42b903418eJohann// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251b362b15af34006e6a11974088a46d42b903418eJohann// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261b362b15af34006e6a11974088a46d42b903418eJohann// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271b362b15af34006e6a11974088a46d42b903418eJohann// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
281b362b15af34006e6a11974088a46d42b903418eJohann// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291b362b15af34006e6a11974088a46d42b903418eJohann//
301b362b15af34006e6a11974088a46d42b903418eJohann// Author: preston.a.jackson@gmail.com (Preston Jackson)
311b362b15af34006e6a11974088a46d42b903418eJohann//
321b362b15af34006e6a11974088a46d42b903418eJohann// Google Test - FrameworkSample
331b362b15af34006e6a11974088a46d42b903418eJohann// widget.cc
341b362b15af34006e6a11974088a46d42b903418eJohann//
351b362b15af34006e6a11974088a46d42b903418eJohann
361b362b15af34006e6a11974088a46d42b903418eJohann// Widget is a very simple class used for demonstrating the use of gtest
371b362b15af34006e6a11974088a46d42b903418eJohann
381b362b15af34006e6a11974088a46d42b903418eJohann#include "widget.h"
391b362b15af34006e6a11974088a46d42b903418eJohann
401b362b15af34006e6a11974088a46d42b903418eJohannWidget::Widget(int number, const std::string& name)
411b362b15af34006e6a11974088a46d42b903418eJohann    : number_(number),
421b362b15af34006e6a11974088a46d42b903418eJohann      name_(name) {}
431b362b15af34006e6a11974088a46d42b903418eJohann
441b362b15af34006e6a11974088a46d42b903418eJohannWidget::~Widget() {}
451b362b15af34006e6a11974088a46d42b903418eJohann
461b362b15af34006e6a11974088a46d42b903418eJohannfloat Widget::GetFloatValue() const {
471b362b15af34006e6a11974088a46d42b903418eJohann  return number_;
481b362b15af34006e6a11974088a46d42b903418eJohann}
491b362b15af34006e6a11974088a46d42b903418eJohann
501b362b15af34006e6a11974088a46d42b903418eJohannint Widget::GetIntValue() const {
511b362b15af34006e6a11974088a46d42b903418eJohann  return static_cast<int>(number_);
521b362b15af34006e6a11974088a46d42b903418eJohann}
531b362b15af34006e6a11974088a46d42b903418eJohann
541b362b15af34006e6a11974088a46d42b903418eJohannstd::string Widget::GetStringValue() const {
551b362b15af34006e6a11974088a46d42b903418eJohann  return name_;
561b362b15af34006e6a11974088a46d42b903418eJohann}
571b362b15af34006e6a11974088a46d42b903418eJohann
581b362b15af34006e6a11974088a46d42b903418eJohannvoid Widget::GetCharPtrValue(char* buffer, size_t max_size) const {
591b362b15af34006e6a11974088a46d42b903418eJohann  // Copy the char* representation of name_ into buffer, up to max_size.
601b362b15af34006e6a11974088a46d42b903418eJohann  strncpy(buffer, name_.c_str(), max_size-1);
611b362b15af34006e6a11974088a46d42b903418eJohann  buffer[max_size-1] = '\0';
621b362b15af34006e6a11974088a46d42b903418eJohann  return;
631b362b15af34006e6a11974088a46d42b903418eJohann}
64