1a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// Copyright 2008, Google Inc. 2a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// All rights reserved. 3a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// 4a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// Redistribution and use in source and binary forms, with or without 5a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// modification, are permitted provided that the following conditions are 6a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// met: 7a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// 8a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// * Redistributions of source code must retain the above copyright 9a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// notice, this list of conditions and the following disclaimer. 10a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// * Redistributions in binary form must reproduce the above 11a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// copyright notice, this list of conditions and the following disclaimer 12a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// in the documentation and/or other materials provided with the 13a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// distribution. 14a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// * Neither the name of Google Inc. nor the names of its 15a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// contributors may be used to endorse or promote products derived from 16a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// this software without specific prior written permission. 17a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// 18a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// 302b608176ebb3ae26cd536dbb5809d6941affec33preston.a.jackson// Author: preston.a.jackson@gmail.com (Preston Jackson) 31a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// 32a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// Google Test - FrameworkSample 33a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// widget.cc 34a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// 35a87cf522c7fae909db136aafd5374e16c7ce8497shiqian 36a87cf522c7fae909db136aafd5374e16c7ce8497shiqian// Widget is a very simple class used for demonstrating the use of gtest 37a87cf522c7fae909db136aafd5374e16c7ce8497shiqian 38a87cf522c7fae909db136aafd5374e16c7ce8497shiqian#include "widget.h" 39a87cf522c7fae909db136aafd5374e16c7ce8497shiqian 40a87cf522c7fae909db136aafd5374e16c7ce8497shiqianWidget::Widget(int number, const std::string& name) 41a87cf522c7fae909db136aafd5374e16c7ce8497shiqian : number_(number), 42a87cf522c7fae909db136aafd5374e16c7ce8497shiqian name_(name) {} 43a87cf522c7fae909db136aafd5374e16c7ce8497shiqian 44a87cf522c7fae909db136aafd5374e16c7ce8497shiqianWidget::~Widget() {} 452b608176ebb3ae26cd536dbb5809d6941affec33preston.a.jackson 46a87cf522c7fae909db136aafd5374e16c7ce8497shiqianfloat Widget::GetFloatValue() const { 47a87cf522c7fae909db136aafd5374e16c7ce8497shiqian return number_; 48a87cf522c7fae909db136aafd5374e16c7ce8497shiqian} 49a87cf522c7fae909db136aafd5374e16c7ce8497shiqian 50a87cf522c7fae909db136aafd5374e16c7ce8497shiqianint Widget::GetIntValue() const { 51a87cf522c7fae909db136aafd5374e16c7ce8497shiqian return static_cast<int>(number_); 52a87cf522c7fae909db136aafd5374e16c7ce8497shiqian} 532b608176ebb3ae26cd536dbb5809d6941affec33preston.a.jackson 54a87cf522c7fae909db136aafd5374e16c7ce8497shiqianstd::string Widget::GetStringValue() const { 55a87cf522c7fae909db136aafd5374e16c7ce8497shiqian return name_; 56a87cf522c7fae909db136aafd5374e16c7ce8497shiqian} 57a87cf522c7fae909db136aafd5374e16c7ce8497shiqian 58a87cf522c7fae909db136aafd5374e16c7ce8497shiqianvoid Widget::GetCharPtrValue(char* buffer, size_t max_size) const { 59a87cf522c7fae909db136aafd5374e16c7ce8497shiqian // Copy the char* representation of name_ into buffer, up to max_size. 60a87cf522c7fae909db136aafd5374e16c7ce8497shiqian strncpy(buffer, name_.c_str(), max_size-1); 61a87cf522c7fae909db136aafd5374e16c7ce8497shiqian buffer[max_size-1] = '\0'; 62a87cf522c7fae909db136aafd5374e16c7ce8497shiqian return; 63a87cf522c7fae909db136aafd5374e16c7ce8497shiqian} 64