cunit-testingcheck-framework

How to write Check test makefile.am with multipe source file and header?


Did anyone know how to write Check makefile.am if we have more than *.c file in the test code? Example:

#include "../src/SpeedGauge.h"
#include "../src/CruiseManager.h"
#include "../src/Throttle.h"

SpeedGauge speedo;
CruiseManager controller;
Throttle throttle;

/* Test case for  - Case1 */
START_TEST (test_Case1)
{
    int expected = 11; // TODO: Initialize to an appropriate value
    speedo.time = 1111; // TODO: Initialize to an appropriate value
    speedo.rotaryCount = 3333; // TODO: Initialize to an appropriate value

    // tick: 1
    SpeedGauge_calcSpeed(&speedo);
    CruiseManager_set(&controller);
    Throttle_normal(&throttle);

    int result = throttle.throttleVal;

    fail_unless (result == expected, "Expecting <%i> instead of <%i>", expected, result);
}
END_TEST

This is my makefile.am:

## Process this file with automake to produce Makefile.in

lib_LTLIBRARIES = libSpeedGauge.la libCruiseManager.la libThrottle.la
libSpeedGauge_la_SOURCES = SpeedGauge.c SpeedGauge.h CruiseManager.c CruiseManager.h Throttle.c Throttle.h

bin_PROGRAMS = main
main_SOURCES = main.c
main_LDADD = libSpeedGauge.la libCruiseManager.la libThrottle.la

I got an error saying this:

libtool: link: ranlib .libs/libSpeedGauge.a
libtool: link: ( cd ".libs" && rm -f "libSpeedGauge.la" && ln -s "../libSpeedGauge.la" "libSpeedGauge.la" )
make[2]: *** No rule to make target `libCruiseManager.lo', needed by `libCruiseManager.la'.  Stop.
make[2]: Leaving directory `/home/mjaa001/Desktop/cruisecontrol/src'
make[1]: *** [all-recursive] Error 1

It seem that it can't link the compile code. Did I specify the lib class wrongly or I need a single class file only?

Update

Solve by editing the makefile.am from

libSpeedGauge_la_SOURCES = SpeedGauge.c SpeedGauge.h CruiseManager.c CruiseManager.h Throttle.c Throttle.h

to

libSpeedGauge_la_SOURCES = SpeedGauge.c SpeedGauge.h
libCruiseManager_la_SOURCES = CruiseManager.c CruiseManager.h
libThrottle_la_SOURCES = Throttle.c Throttle.h

Solution

  • lib_LTLIBRARIES = libSpeedGauge.la libCruiseManager.la libThrottle.la
    
    libCruiseManager_la_SOURCES = ...
    

    or

    ## Process this file with automake to produce Makefile.in
    
    lib_LTLIBRARIES = libSpeedGauge.la
    libSpeedGauge_la_SOURCES = SpeedGauge.c CruiseManager.c Throttle.c
    
    bin_PROGRAMS = main
    main_SOURCES = main.c
    main_LDADD = libSpeedGauge.la