Commit bc378c70 authored by Eric Fossum's avatar Eric Fossum

Passing all CPP UTests

Still needs LinuxI2c constructor tests.
parent 3c14e445
......@@ -43,12 +43,11 @@ TESTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tests
# Test Files
TESTFILES= \
${TESTDIR}/TestFiles/f3 \
${TESTDIR}/TestFiles/f1
${TESTDIR}/TestFiles/f3
# Test Object Files
TESTOBJECTFILES= \
${TESTDIR}/tests/emc1072test.o \
${TESTDIR}/tests/emc1072testclass.o \
${TESTDIR}/tests/i2ctestrunner.o \
${TESTDIR}/tests/linuxi2ctestclass.o
......@@ -93,13 +92,15 @@ ${OBJECTDIR}/src/linux-i2c.o: src/linux-i2c.cpp
.build-tests-conf: .build-tests-subprojects .build-conf ${TESTFILES}
.build-tests-subprojects:
${TESTDIR}/TestFiles/f3: ${TESTDIR}/tests/i2ctestrunner.o ${TESTDIR}/tests/linuxi2ctestclass.o ${OBJECTFILES:%.o=%_nomain.o}
${TESTDIR}/TestFiles/f3: ${TESTDIR}/tests/emc1072testclass.o ${TESTDIR}/tests/i2ctestrunner.o ${TESTDIR}/tests/linuxi2ctestclass.o ${OBJECTFILES:%.o=%_nomain.o}
${MKDIR} -p ${TESTDIR}/TestFiles
${LINK.cc} -o ${TESTDIR}/TestFiles/f3 $^ ${LDLIBSOPTIONS} `cppunit-config --libs`
${TESTDIR}/TestFiles/f1: ${TESTDIR}/tests/emc1072test.o ${OBJECTFILES:%.o=%_nomain.o}
${MKDIR} -p ${TESTDIR}/TestFiles
${LINK.cc} -o ${TESTDIR}/TestFiles/f1 $^ ${LDLIBSOPTIONS}
${TESTDIR}/tests/emc1072testclass.o: tests/emc1072testclass.cpp
${MKDIR} -p ${TESTDIR}/tests
${RM} "$@.d"
$(COMPILE.cc) -g -Iinclude -std=c++98 `cppunit-config --cflags` -MMD -MP -MF "$@.d" -o ${TESTDIR}/tests/emc1072testclass.o tests/emc1072testclass.cpp
${TESTDIR}/tests/i2ctestrunner.o: tests/i2ctestrunner.cpp
......@@ -114,12 +115,6 @@ ${TESTDIR}/tests/linuxi2ctestclass.o: tests/linuxi2ctestclass.cpp
$(COMPILE.cc) -g -Iinclude -std=c++98 `cppunit-config --cflags` -MMD -MP -MF "$@.d" -o ${TESTDIR}/tests/linuxi2ctestclass.o tests/linuxi2ctestclass.cpp
${TESTDIR}/tests/emc1072test.o: tests/emc1072test.cpp
${MKDIR} -p ${TESTDIR}/tests
${RM} "$@.d"
$(COMPILE.cc) -g -Iinclude -I. -std=c++98 -MMD -MP -MF "$@.d" -o ${TESTDIR}/tests/emc1072test.o tests/emc1072test.cpp
${OBJECTDIR}/src/emc1072_nomain.o: ${OBJECTDIR}/src/emc1072.o src/emc1072.cpp
${MKDIR} -p ${OBJECTDIR}/src
@NMOUTPUT=`${NM} ${OBJECTDIR}/src/emc1072.o`; \
......@@ -151,7 +146,6 @@ ${OBJECTDIR}/src/linux-i2c_nomain.o: ${OBJECTDIR}/src/linux-i2c.o src/linux-i2c.
@if [ "${TEST}" = "" ]; \
then \
${TESTDIR}/TestFiles/f3 || true; \
${TESTDIR}/TestFiles/f1 || true; \
else \
./${TEST} || true; \
fi
......
......@@ -43,12 +43,11 @@ TESTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tests
# Test Files
TESTFILES= \
${TESTDIR}/TestFiles/f3 \
${TESTDIR}/TestFiles/f1
${TESTDIR}/TestFiles/f3
# Test Object Files
TESTOBJECTFILES= \
${TESTDIR}/tests/emc1072test.o \
${TESTDIR}/tests/emc1072testclass.o \
${TESTDIR}/tests/i2ctestrunner.o \
${TESTDIR}/tests/linuxi2ctestclass.o
......@@ -93,13 +92,15 @@ ${OBJECTDIR}/src/linux-i2c.o: src/linux-i2c.cpp
.build-tests-conf: .build-tests-subprojects .build-conf ${TESTFILES}
.build-tests-subprojects:
${TESTDIR}/TestFiles/f3: ${TESTDIR}/tests/i2ctestrunner.o ${TESTDIR}/tests/linuxi2ctestclass.o ${OBJECTFILES:%.o=%_nomain.o}
${TESTDIR}/TestFiles/f3: ${TESTDIR}/tests/emc1072testclass.o ${TESTDIR}/tests/i2ctestrunner.o ${TESTDIR}/tests/linuxi2ctestclass.o ${OBJECTFILES:%.o=%_nomain.o}
${MKDIR} -p ${TESTDIR}/TestFiles
${LINK.cc} -o ${TESTDIR}/TestFiles/f3 $^ ${LDLIBSOPTIONS} `cppunit-config --libs`
${TESTDIR}/TestFiles/f1: ${TESTDIR}/tests/emc1072test.o ${OBJECTFILES:%.o=%_nomain.o}
${MKDIR} -p ${TESTDIR}/TestFiles
${LINK.cc} -o ${TESTDIR}/TestFiles/f1 $^ ${LDLIBSOPTIONS}
${TESTDIR}/tests/emc1072testclass.o: tests/emc1072testclass.cpp
${MKDIR} -p ${TESTDIR}/tests
${RM} "$@.d"
$(COMPILE.cc) -O2 `cppunit-config --cflags` -MMD -MP -MF "$@.d" -o ${TESTDIR}/tests/emc1072testclass.o tests/emc1072testclass.cpp
${TESTDIR}/tests/i2ctestrunner.o: tests/i2ctestrunner.cpp
......@@ -114,12 +115,6 @@ ${TESTDIR}/tests/linuxi2ctestclass.o: tests/linuxi2ctestclass.cpp
$(COMPILE.cc) -O2 `cppunit-config --cflags` -MMD -MP -MF "$@.d" -o ${TESTDIR}/tests/linuxi2ctestclass.o tests/linuxi2ctestclass.cpp
${TESTDIR}/tests/emc1072test.o: tests/emc1072test.cpp
${MKDIR} -p ${TESTDIR}/tests
${RM} "$@.d"
$(COMPILE.cc) -O2 -I. -MMD -MP -MF "$@.d" -o ${TESTDIR}/tests/emc1072test.o tests/emc1072test.cpp
${OBJECTDIR}/src/emc1072_nomain.o: ${OBJECTDIR}/src/emc1072.o src/emc1072.cpp
${MKDIR} -p ${OBJECTDIR}/src
@NMOUTPUT=`${NM} ${OBJECTDIR}/src/emc1072.o`; \
......@@ -151,7 +146,6 @@ ${OBJECTDIR}/src/linux-i2c_nomain.o: ${OBJECTDIR}/src/linux-i2c.o src/linux-i2c.
@if [ "${TEST}" = "" ]; \
then \
${TESTDIR}/TestFiles/f3 || true; \
${TESTDIR}/TestFiles/f1 || true; \
else \
./${TEST} || true; \
fi
......
......@@ -26,16 +26,12 @@
displayName="CppUnit Tests"
projectFiles="true"
kind="TEST">
<itemPath>tests/emc1072testclass.cpp</itemPath>
<itemPath>tests/emc1072testclass.h</itemPath>
<itemPath>tests/i2ctestrunner.cpp</itemPath>
<itemPath>tests/linuxi2ctestclass.cpp</itemPath>
<itemPath>tests/linuxi2ctestclass.h</itemPath>
</logicalFolder>
<logicalFolder name="f1"
displayName="EMC1072 Test"
projectFiles="true"
kind="TEST">
<itemPath>tests/emc1072test.cpp</itemPath>
</logicalFolder>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
......@@ -68,21 +64,6 @@
<commandLine>-v</commandLine>
</linkerTool>
</compileType>
<folder path="TestFiles/f1">
<cTool>
<incDir>
<pElem>.</pElem>
</incDir>
</cTool>
<ccTool>
<incDir>
<pElem>.</pElem>
</incDir>
</ccTool>
<linkerTool>
<output>${TESTDIR}/TestFiles/f1</output>
</linkerTool>
</folder>
<folder path="TestFiles/f3">
<cTool>
<commandLine>`cppunit-config --cflags`</commandLine>
......@@ -107,7 +88,9 @@
</item>
<item path="src/linux-i2c.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="tests/emc1072test.cpp" ex="false" tool="1" flavor2="0">
<item path="tests/emc1072testclass.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="tests/emc1072testclass.h" ex="false" tool="3" flavor2="0">
</item>
<item path="tests/i2ctestrunner.cpp" ex="false" tool="1" flavor2="0">
</item>
......@@ -136,21 +119,6 @@
<developmentMode>5</developmentMode>
</asmTool>
</compileType>
<folder path="TestFiles/f1">
<cTool>
<incDir>
<pElem>.</pElem>
</incDir>
</cTool>
<ccTool>
<incDir>
<pElem>.</pElem>
</incDir>
</ccTool>
<linkerTool>
<output>${TESTDIR}/TestFiles/f1</output>
</linkerTool>
</folder>
<folder path="TestFiles/f3">
<cTool>
<commandLine>`cppunit-config --cflags`</commandLine>
......@@ -175,7 +143,9 @@
</item>
<item path="src/linux-i2c.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="tests/emc1072test.cpp" ex="false" tool="1" flavor2="0">
<item path="tests/emc1072testclass.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="tests/emc1072testclass.h" ex="false" tool="3" flavor2="0">
</item>
<item path="tests/i2ctestrunner.cpp" ex="false" tool="1" flavor2="0">
</item>
......
/*
* File: emc1072test.cpp
* Author: ericfoss
*
* Created on February 13, 2017, 7:51 PM
*/
#include <stdlib.h>
#include <iostream>
#include "emc1072.h"
/*
* Simple C++ Test Suite
*/
const char GOOD_ADDR = 0x4c;
const char *GOOD_PATH = "/dev/i2c-2";
void constructor_test() {
Emc1072 i2c(GOOD_PATH, GOOD_ADDR);
}
void internal_temp_test() {
Emc1072 i2c(GOOD_PATH, GOOD_ADDR);
double temp = i2c.internal_temp();
if (temp > 30 || temp < 10) {
std::cout << "%TEST_FAILED% time=0 testname=internal_temp_test (emc1072test) message=Couldn't read temp" << std::endl;
}
}
void external_temp_test() {
Emc1072 i2c(GOOD_PATH, GOOD_ADDR);
double temp = i2c.external_temp();
if (temp > 30 || temp < 10) {
std::cout << "%TEST_FAILED% time=0 testname=external_temp_test (emc1072test) message=Couldn't read temp" << std::endl;
}
}
void c_to_f_test() {
double temp = Emc1072::c_to_f(0);
if (temp != 32) {
std::cout << "%TEST_FAILED% time=0 testname=c_to_f_test (emc1072test) message=Invalid temp conversion " << temp << std::endl;
}
}
void f_to_c_test() {
double temp = Emc1072::f_to_c(32);
if (temp != 0) {
std::cout << "%TEST_FAILED% time=0 testname=f_to_c_test (emc1072test) message=Invalid temp conversion " << temp << std::endl;
}
}
int main(int argc, char** argv) {
std::cout << "%SUITE_STARTING% emc1072test" << std::endl;
std::cout << "%SUITE_STARTED%" << std::endl;
std::cout << "%TEST_STARTED% constructor_test (emc1072test)" << std::endl;
constructor_test();
std::cout << "%TEST_FINISHED% time=0 constructor_test (emc1072test)" << std::endl;
std::cout << "%TEST_STARTED% internal_temp_test (emc1072test)" << std::endl;
internal_temp_test();
std::cout << "%TEST_FINISHED% time=0 internal_temp_test (emc1072test)" << std::endl;
std::cout << "%TEST_STARTED% external_temp_test (emc1072test)" << std::endl;
external_temp_test();
std::cout << "%TEST_FINISHED% time=0 external_temp_test (emc1072test)" << std::endl;
std::cout << "%TEST_STARTED% c_to_f_test (emc1072test)" << std::endl;
c_to_f_test();
std::cout << "%TEST_FINISHED% time=0 c_to_f_test (emc1072test)" << std::endl;
std::cout << "%TEST_STARTED% f_to_c_test (emc1072test)" << std::endl;
f_to_c_test();
std::cout << "%TEST_FINISHED% time=0 f_to_c_test (emc1072test)" << std::endl;
std::cout << "%SUITE_FINISHED% time=0" << std::endl;
return (EXIT_SUCCESS);
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: emc1072testclass.cpp
* Author: ericfoss
*
* Created on Feb 15, 2017, 7:24:07 AM
*/
#include "emc1072testclass.h"
CPPUNIT_TEST_SUITE_REGISTRATION(emc1072testclass);
emc1072testclass::emc1072testclass() {
}
emc1072testclass::~emc1072testclass() {
}
void emc1072testclass::setUp() {
obj = new Emc1072("/dev/i2c-2", 0x4c);
}
void emc1072testclass::tearDown() {
if (obj) {
delete(obj);
}
}
void emc1072testclass::internal_temp_test() {
double temp = obj->internal_temp();
CPPUNIT_ASSERT(temp < 30 && temp > 10);
}
void emc1072testclass::external_temp_test() {
double temp = obj->external_temp();
CPPUNIT_ASSERT(temp < 30 && temp > 10);
}
void emc1072testclass::c_to_f_test() {
double temp = Emc1072::c_to_f(0);
CPPUNIT_ASSERT(temp == 32);
}
void emc1072testclass::f_to_c_test() {
double temp = Emc1072::f_to_c(32);
CPPUNIT_ASSERT(temp == 0);
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: emc1072testclass.h
* Author: ericfoss
*
* Created on Feb 15, 2017, 7:24:07 AM
*/
#ifndef EMC1072TESTCLASS_H
#define EMC1072TESTCLASS_H
#include <cppunit/extensions/HelperMacros.h>
#include "../include/emc1072.h"
class emc1072testclass : public CPPUNIT_NS::TestFixture {
CPPUNIT_TEST_SUITE(emc1072testclass);
CPPUNIT_TEST(internal_temp_test);
CPPUNIT_TEST(external_temp_test);
CPPUNIT_TEST(c_to_f_test);
CPPUNIT_TEST(f_to_c_test);
CPPUNIT_TEST_SUITE_END();
public:
emc1072testclass();
virtual ~emc1072testclass();
void setUp();
void tearDown();
private:
void internal_temp_test();
void external_temp_test();
void c_to_f_test();
void f_to_c_test();
Emc1072 *obj;
};
#endif /* EMC1072TESTCLASS_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment