Files
epics-base/modules/database/test/std/rec/longoutTest.c
2021-03-09 16:31:54 +01:00

215 lines
6.6 KiB
C

/*************************************************************************\
* Copyright (c) 2020 Joao Paulo Martins
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#include "dbUnitTest.h"
#include "testMain.h"
#include "dbLock.h"
#include "errlog.h"
#include "dbAccess.h"
#include "epicsMath.h"
#include "longoutRecord.h"
void recTestIoc_registerRecordDeviceDriver(struct dbBase *);
static void test_oopt_everytime(void){
/* reset rec processing counter */
testdbPutFieldOk("counter.VAL", DBF_DOUBLE, 0.0);
/* write the same value two times */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
/* write two times with different values*/
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 17);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 18);
/* Test if the counter was processed 4 times */
testdbGetFieldEqual("counter", DBF_DOUBLE, 4.0);
// number of tests = 6
}
static void test_oopt_onchange(void){
/* change OOPT to On Change */
testdbPutFieldOk("longout_rec.OOPT", DBF_ENUM, longoutOOPT_On_Change);
/* reset rec processing counter */
testdbPutFieldOk("counter.VAL", DBF_DOUBLE, 0.0);
/* write the same value two times */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
/* Test if the counter was processed only once */
testdbGetFieldEqual("counter", DBF_DOUBLE, 1.0);
/* write two times with different values*/
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 17);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 18);
/* Test if the counter was processed 1 + 2 times */
testdbGetFieldEqual("counter", DBF_DOUBLE, 3.0);
//number of tests 8
}
static void test_oopt_whenzero(void){
testdbPutFieldOk("longout_rec.OOPT", DBF_ENUM, longoutOOPT_When_Zero);
/* reset rec processing counter */
testdbPutFieldOk("counter.VAL", DBF_DOUBLE, 0.0);
/* write zero two times */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 0);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 0);
/* Test if the counter was processed twice */
testdbGetFieldEqual("counter", DBF_DOUBLE, 2.0);
/* write two times with non-zero values*/
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 17);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 18);
/* Test if the counter was still processed 2 times */
testdbGetFieldEqual("counter", DBF_DOUBLE, 2.0);
//number of tests 8
}
static void test_oopt_whennonzero(void){
testdbPutFieldOk("longout_rec.OOPT", DBF_ENUM, longoutOOPT_When_Non_zero);
/* reset rec processing counter */
testdbPutFieldOk("counter.VAL", DBF_DOUBLE, 0.0);
/* write zero two times */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 0);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 0);
/* Test if the counter was never processed */
testdbGetFieldEqual("counter", DBF_DOUBLE, 0.0);
/* write two times with non-zero values*/
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 17);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 18);
/* Test if the counter was still processed 2 times */
testdbGetFieldEqual("counter", DBF_DOUBLE, 2.0);
//number of tests 8
}
static void test_oopt_when_transition_zero(void){
testdbPutFieldOk("longout_rec.OOPT", DBF_ENUM, longoutOOPT_Transition_To_Zero);
/* reset rec processing counter */
testdbPutFieldOk("counter.VAL", DBF_DOUBLE, 0.0);
/* write non-zero then zero */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 0);
/* Test if the counter was processed */
testdbGetFieldEqual("counter", DBF_DOUBLE, 1.0);
/* write another transition to zero */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 17);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 0);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 17);
/* Test if the counter was processed once more */
testdbGetFieldEqual("counter", DBF_DOUBLE, 2.0);
//number of tests 9
}
static void test_oopt_when_transition_nonzero(void){
testdbPutFieldOk("longout_rec.OOPT", DBF_ENUM, longoutOOPT_Transition_To_Non_zero);
/* write non-zero to start fresh */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
/* reset rec processing counter */
testdbPutFieldOk("counter.VAL", DBF_DOUBLE, 0.0);
/* write non-zero then zero */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 17);
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 0);
/* Test if the counter was never processed */
testdbGetFieldEqual("counter", DBF_DOUBLE, 0.0);
/* write a transition to non-zero */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 18);
/* Test if the counter was processed */
testdbGetFieldEqual("counter", DBF_DOUBLE, 1.0);
//number of tests 8
}
static void test_changing_out_field(void){
/* change OOPT to On Change */
testdbPutFieldOk("longout_rec.OOPT", DBF_ENUM, longoutOOPT_On_Change);
/* write an initial value */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
/* reset rec processing counter */
testdbPutFieldOk("counter.VAL", DBF_DOUBLE, 0.0);
testdbPutFieldOk("counter2.VAL", DBF_DOUBLE, 0.0);
/* write the same value */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
/* Test if the counter was never processed */
testdbGetFieldEqual("counter", DBF_DOUBLE, 0.0);
/* change the OUT link to another counter */
testdbPutFieldOk("longout_rec.OUT", DBF_STRING, "counter2.B PP");
/* write the same value */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
/* Test if the counter was processed once */
testdbGetFieldEqual("counter2", DBF_DOUBLE, 1.0);
/* write the same value */
testdbPutFieldOk("longout_rec.VAL", DBF_LONG, 16);
/* Test if the counter was not processed again */
testdbGetFieldEqual("counter2", DBF_DOUBLE, 1.0);
}
MAIN(longoutTest) {
testPlan(6+8+8+8+9+8+11);
testdbPrepare();
testdbReadDatabase("recTestIoc.dbd", NULL, NULL);
recTestIoc_registerRecordDeviceDriver(pdbbase);
testdbReadDatabase("longoutTest.db", NULL, NULL);
eltc(0);
testIocInitOk();
eltc(1);
test_oopt_everytime();
test_oopt_onchange();
test_oopt_whenzero();
test_oopt_whennonzero();
test_oopt_when_transition_zero();
test_oopt_when_transition_nonzero();
test_changing_out_field();
testIocShutdownOk();
testdbCleanup();
return testDone();
}