CppUnit


 
Thread Tools Search this Thread
Top Forums Programming CppUnit
# 1  
Old 02-04-2010
CppUnit

Hey guys, i am trying to test one of my classes using cppunit.

the class is suppose to extract data out of a certain text file and then displays it...

v
Code:
oid readNasdaq::Nasdaq(fstream&  myfile)
{
    string templine ;
    string line;

    while (getline (myfile,templine) )
    {
        line.append(templine);
    }

    int NasdaqValueID = line.find ("id=\"yfs_l10_^ixic\">" , 0) ;
    int NasdaqValueCount = line.find ("</span></td><td class=\"ticker_down\"><span class=\"streaming-datum\" id=\"yfs_c10_^ixic\">" , 0) ;

    int LocationNasdaqValue = NasdaqValueID + 19 ;
    int LengthOfNasdaqValue = NasdaqValueCount - LocationNasdaqValue ;

string NasdaqValue = line.substr( LocationNasdaqValue , LengthOfNasdaqValue ) ;

   cout << "  " << endl ;
cout << "The Value Index of Nasdaq is " << NasdaqValue << endl ;


int NasdaqValueChangeID = line.find ("id=\"yfs_c10_^ixic\">" , 0 ) ;
int NasdaqValueChangeCount = line.find ("</span></td><td class=\"right_cell ticker_down\"><span class=\"streaming-datum\" id=\"yfs_pp0_^ixic\">" , 0) ;

int LocationNasdaqValueChange = NasdaqValueChangeID + 19 ;
int LengthOfNasdaqValueChange = NasdaqValueChangeCount - LocationNasdaqValueChange ;

string NasdaqValueChange = line.substr (LocationNasdaqValueChange , LengthOfNasdaqValueChange ) ;

cout << "The Value Change for Nasdaq is " << NasdaqValueChange << endl ;

the problem i have with my cppunit is how am i suppose to read the value being outputted and test it...

Code:
#include "financetest.h"
#include "finance.h"



CPPUNIT_TEST_SUITE_REGISTRATION (FinanceTest);



void FinanceTest::setUp()
{
    New = " ";
    NewValue = " " ;


}

void FinanceTest::tearDown()
{
    
}

void FinanceTest::testEquals()
{
    
    }

This is how far i got. Can anybody give me some clue on how to continue.
# 2  
Old 02-04-2010
Read which value? There's several things being outputted here.

It doesn't look like the code there actually stores the results, just prints them, which will make them extremely hard to get. It should be putting them in class members instead of local variables, so other things can get at them later. How to use it depends wholly on what accessors the class has, too, which we don't know!
# 3  
Old 02-04-2010
Hmm, the values i want is in string NasdaqValue and string NasdaqValueChange. SOrry but can i ask how do u put them in class members and why cant it be stored in local variables.
# 4  
Old 02-04-2010
Because those variables cease to exist when the function returns. If you want them stored any longer, you should either put them through as a function return value or store them in something more permanent.

To store them in an object member:
  1. Add a member of the correct type to the object to store it in.

    Code:
    class wtf
    {
    public:
            int value;
    };

  2. Store it in it.

    Code:
    class wtf
    {
    public:
            wtf() { value=3; }
            int value;
    }

  3. It is now available to be read by other things.

    Code:
    wtf w();
    
    cout "value=" << w.value << "\n";

Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Programming

Understanding cppUnit.

Hey guys, i am doing a project which has to incorporate some unit testing using cPPUnit. i am unable to actually find some proper tutorials which is good for a beginner like me. Could you guys help in giving me some tutorials,examples or links where i am able to understand how is it being used? (1 Reply)
Discussion started by: gregarion
1 Replies
Login or Register to Ask a Question