Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Added Google Test (Native U++ plugin via plugin/gtest)
Added Google Test [message #45907] Sun, 24 January 2016 14:15 Go to previous message
Klugier is currently offline  Klugier
Messages: 1076
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

Google Test is a unit test framework for C++. More information about library you can find on official GitHub project site: https://github.com/google/googletest.

This is native upp plugin, so it doesn't require any additional dependency. In addition it offers fast creating of test package via TheIDE template mechanism. Currently it's supporting MS Windows and GNU/Linux.

Current u++ port require dependency with Core package. This is because Google Test in one place has got memory leak and I manually turn it off via Upp::MemoryIgnoreLeaksBegin() and Upp::MemoryIgnoreLeaksEnd().

Below is the simply example that shows how to test Upp Core package (bazzar/GoogleTestExample):
StringTest.h:
#ifndef _GoogleTestExample_VectorTest_h_
#define _GoogleTestExample_VectorTest_h_

#include <Core/Core.h>
#include <plugin/gtest/gtest.h>

NAMESPACE_UPP

class StringTest : public testing::Test {
protected:
	virtual void SetUp();
	
protected:
	String sEmpty;
	String sCat;
	String sDog;
};

END_UPP_NAMESPACE

#endif


StringTest.h:
#include "StringTest.h"

NAMESPACE_UPP

void StringTest::SetUp()
{
	sCat = "Cat";
	sDog = "Dog";
}

TEST_F(StringTest, TestDefaultConstructor)
{
	String a;
	
	ASSERT_EQ(a, "");
}

TEST_F(StringTest, TestConstructor)
{
	String a("Test");
	ASSERT_EQ(a, "Test");
}

TEST_F(StringTest, TestGetCount)
{
	ASSERT_EQ(sEmpty.GetCount(), 0);
	ASSERT_EQ(sCat.GetCount(), 3);
	ASSERT_EQ(sDog.GetCount(), 3);
}

TEST_F(StringTest, TestClear)
{
	sCat.Clear();
	
	ASSERT_EQ(sCat, "");
	ASSERT_EQ(sCat.GetCount(), 0);
}

TEST_F(StringTest, TestCompare)
{
	ASSERT_EQ(sCat.Compare(sCat), 0);
	ASSERT_EQ(sCat.Compare(sDog), -1);
}

TEST_F(StringTest, TestEqual)
{
	ASSERT_TRUE(sCat.IsEqual(sCat));
	ASSERT_FALSE(sCat.IsEqual(sDog));
}

END_UPP_NAMESPACE


main.cpp
#include <plugin/gtest/gtest.h>

int main(int argc, char *argv[])
{
	testing::InitGoogleTest(&argc, argv);
	
	return RUN_ALL_TESTS();
}


Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Sun, 24 January 2016 14:20]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Repgen package
Next Topic: JobQueue: A simple and programmable job/queue model.
Goto Forum:
  


Current Time: Fri Apr 26 13:33:52 CEST 2024

Total time taken to generate the page: 0.07266 seconds