How do i declare my struct for test functions?

This is a discussion on How do i declare my struct for test functions? within the C Programming forums, part of the General Programming Boards category; This is just a header file with my typedefs declared. I need to make test functions for every one of ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    33

    How do i declare my struct for test functions?

    This is just a header file with my typedefs declared. I need to make test functions for every one of these functions below. How would i declare the parameters in the functions so that they can be tested? Like what would i set Rcb *B and ELEMENT_TYPE x to so i can run test functions. Sorry if this is confusing to you, i am a begginner

    Code:
    typedef char ELEMENT_TYPE[1024];
    
    typedef struct data
    {
    	ELEMENT_TYPE element;
    	struct data *previous;
    	struct data *next;
    } Data;
    
    typedef struct
    {
    	int size;
    	Data *spot;
    } Rcb;
    
    //  FUNCTION PROTOTYPES
    
    Rcb *Create(void);
    void Dispose (Rcb *B);
    void InsertBefore (ELEMENT_TYPE x, Rcb *B);
    void InsertAfter (ELEMENT_TYPE x, Rcb *B);
    void Find (ELEMENT_TYPE x, Rcb *B);
    void Read (void);
    void Write (ELEMENT_TYPE x, Rcb *B);
    void Remove (Rcb *B);
    void Next (Rcb *B);
    void Previous (Rcb *B);
    void Clear (Rcb *B);
    int Size (Rcb *B);
    int isEmpty (Rcb *B);
    void Report (Rcb *B);

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I don't know what you are trying to say. What is a "test function for every one of these functions"?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    I think he means that he needs to implement these functions based on the above given prototypes. I'm sure you have had those homework problems before. Given this, do that etc.

    If that's the case then here is the homework policy

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    33
    Ok so i have two different projects in my solution. The first project contains the actual functions to make a circular buffer and in the second project i need to have test functions that make sure that the acutal functions work. The test functions will be the only things that are going to be ran in the main which each test function is going to print to screen whether the function passed or failed. Does that make sense? And i am confused on how to declare my struct so that it can be used in the test functions.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,652
    Yes, it makes sense: you're asking how to write unit tests. As a simple approach, you can make it such that each test function takes no arguments and returns nothing. Within the function, it creates and tests as needed.

    EDIT:
    Maybe not return nothing: it could return a value indicating pass/fail.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    2,027
    I think he wants to know how to write bunch of unit tests. Google or google video for "How to write good unit tests" may give good results.

    Here's one:How to Write Good Unit Tests - developer.force.com

    The examples aren't C, but you can probably figure them out.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    33
    Well i know to write the test functions........but i don't know to to declare Rcb *B and ELEMENT_TYPE x so that they will work in the test functions. if i know how to do that then i will be golden.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,652
    Quote Originally Posted by lilbo4231
    but i don't know to to declare Rcb *B and ELEMENT_TYPE x so that they will work in the test functions.
    Declare them as you would use them in a main function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Feb 2011
    Posts
    33
    can you give me an example?

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,652
    Quote Originally Posted by lilbo4231
    can you give me an example?
    Looking at the interface of functions that you are supposed to implement, I would expect:
    Code:
    Rcb *rcb = Create();
    /* test a function */
    Dispose(rcb);
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC lets you forward declare a struct with "class /name/"
    By Mozza314 in forum C++ Programming
    Replies: 12
    Last Post: 02-20-2011, 03:52 AM
  2. Replies: 9
    Last Post: 07-23-2010, 06:31 PM
  3. struct pointers and functions
    By alfaceor in forum C Programming
    Replies: 8
    Last Post: 10-20-2009, 09:11 AM
  4. declare and initialize struct members
    By Mr.Bit in forum C Programming
    Replies: 3
    Last Post: 11-23-2007, 10:57 AM
  5. Replies: 2
    Last Post: 05-04-2003, 05:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21