473,388 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Boost unittest

I am using boost for unittesting. But I would like to make a global
container with some content that can be used in all the boost functions:
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
// Boost Test declaration and Checking macros
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/test_tools.hpp>

BOOST_AUTO_TEST_SUITE(my_module);
BOOST_AUTO_TEST_SUITE();

// Types
std::vector<intv;
v.push_back(22); //This gives an error!

BOOST_AUTO_TEST_CASE(test_one)
{
int t = *v.begin()
BOOST_CHECK_EQUAL(t,22);
}
BOOST_AUTO_TEST_CASE(test_two)
{
// do som other test
BOOST_CHECK_EQUAL(i,4);
}

BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE(my_always_fail_test_case)
{
BOOST_CHECK(false);
}
BOOST_AUTO_TEST_SUITE_END();

But when I do v.push_back(22); and compile I get:

syntax error : missing ';' before '.'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int

Is it not possible to use global data?
Aug 6 '08 #1
4 2101
On Aug 6, 12:34*pm, "saneman" <as...@asd.comwrote:
// Types
std::vector<intv;
v.push_back(22); * //This gives an error!
You can't use the global namespace for everything. You must use a
function:

std::vector<intinit_v()
{
std::vector<intv;
v.push_back(22);
return v;
}

std::vector<intv = init_v();

There won't be any performance implication.

Ali
Aug 6 '08 #2

<ac******@gmail.comskrev i en meddelelse
news:01**********************************@1g2000pr e.googlegroups.com...
On Aug 6, 12:34 pm, "saneman" <as...@asd.comwrote:
// Types
std::vector<intv;
v.push_back(22); //This gives an error!
You can't use the global namespace for everything.
Out of curiosity why not? Is it a special boost thing?
Aug 6 '08 #3

<ac******@gmail.comskrev i en meddelelse
news:01**********************************@1g2000pr e.googlegroups.com...
On Aug 6, 12:34 pm, "saneman" <as...@asd.comwrote:
// Types
std::vector<intv;
v.push_back(22); //This gives an error!
You can't use the global namespace for everything. You must use a
function:

std::vector<intinit_v()
{
std::vector<intv;
v.push_back(22);
return v;
}

std::vector<intv = init_v();

Another thing I have tried to make the function work on a reference instead:

void init_v(std::vector<int& v_)
{
v_.push_back(22);
}
std::vector<intv;
init_v(v);

But the I get:

missing type specifier - int assumed. Note: C++ does not support default-int

What is wrong with using references?


Aug 6 '08 #4
On Aug 7, 9:18 am, Michael DOUBEZ <michael.dou...@free.frwrote:
saneman a écrit :
<acehr...@gmail.comskrev i en meddelelse
news:01**********************************@1g2000pr e.googlegroups.com...
On Aug 6, 12:34 pm, "saneman" <as...@asd.comwrote:
// Types
std::vector<intv;
v.push_back(22); //This gives an error!
You can't use the global namespace for everything.
Out of curiosity why not? Is it a special boost thing?
It is something specific to many compiled languages: you have
only one entry point of execution (i.e. main() in C++) and
code get executed from there only. The only exception in C++
being the construction of globals for initialisation. In all
cases code is executed from within a function.
Actually, as you point out later, this isn't true of C++. You
can add additional entry points anywhere you like, just by
defining a variable with static lifetime, e.g.:

static bool dummyForInitialization = (startUpFunction(), true) ;

(Generally speaking, I'd prefer having the startUpFunction
return a bool, and drop the comma operator. But I did it this
way to show that it can easily be done with any function.)
Concerning your question:
1. if you need only one value in your global, you can use:
std::vector<intv(1,22);//vector of size one filled with 22
In this particular case, that's obviously the solution. More
generally, however, he could do something like:

std::vector< int v ;
bool dummyForInitialization = (v.push_back( 22 ), true) ;

(I'm not saying that he should, of course:-). Only that the
possibility exists.)
2. For unit test, usual practice is to set up the environement before
the test such that tests are independant.
I'd say that that is almost a requirement, no?

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Aug 7 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
1
by: Thomas Heller | last post by:
I'm trying to integrate some doctest tests with unittest. The tests must be exposed as one or more subclasses of unittest.TestCase, so I'm collecting them with a call to doctest.DocTestSuite(),...
41
by: Roy Smith | last post by:
I've used the standard unittest (pyunit) module on a few projects in the past and have always thought it basicly worked fine but was just a little too complicated for what it did. I'm starting a...
7
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good...
3
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module....
2
by: Oleg Paraschenko | last post by:
Hello, I decided to re-use functionality of "unittest" module for my purposes. More precisely, I have a list of folders. For each folder, code should enter to the folder, execute a command and...
0
by: Chris Fonnesbeck | last post by:
I have built the following unit test, observing the examples laid out in the python docs: class testMCMC(unittest.TestCase): def setUp(self): # Create an instance of the sampler...
1
by: Chris Fonnesbeck | last post by:
I have a module for which I am trying to code a unit test. However, when I run unittest.main(), I get: In : import PyMC In : PyMC.unittest.main() ...
1
by: saneman | last post by:
I have a function that returns a double: double d1 = compute(a,b,c); when I do: std::cout << d1 << std::endl; I get:
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.