Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyz32 committed Jul 31, 2024
1 parent 665dd36 commit a359886
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ test/test.iml
camel.out
install.out
tests.out
/ile/.metadata
/ile/.metadata
bazel-bin
bazel-manzan
bazel-out
bazel-testlogs
6 changes: 6 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
"type": "shell",
"command": "./deployBuildCamelAndTest.sh",
"problemMatcher": []
},
{
"label": "ileUnitTest",
"type": "shell",
"command": "bazel test --cxxopt=-std=c++14 --verbose_failures --test_output=all //:test_util",
"problemMatcher": []
}
]
}
2 changes: 1 addition & 1 deletion ile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ src/mzversion.h:
/qsys.lib/${BUILDLIB}.lib/handler.pgm: /qsys.lib/${BUILDLIB}.lib/handler.module /qsys.lib/${BUILDLIB}.lib/pub_json.module /qsys.lib/${BUILDLIB}.lib/pub_db2.module /qsys.lib/${BUILDLIB}.lib/debug.module /qsys.lib/${BUILDLIB}.lib/pub_db2.module /qsys.lib/${BUILDLIB}.lib/userconf.module

/qsys.lib/${BUILDLIB}.lib/%.pgm:
system "CRTPGM PGM(${BUILDLIB}/$*) MODULE($(patsubst %.module,$(BUILDLIB)/%,$(notdir $^))) ACTGRP(*CALLER) OUTPUT(*PRINT)" > $*.log 2>&1
system "CRTPGM PGM(${BUILDLIB}/$*) MODULE($(patsubst %.module,$(BUILDLIB)/%,$(notdir $^))) ACTGRP(*CALLER)" > $*.log 2>&1

/qsys.lib/${BUILDLIB}.lib/%.module: src/%.cpp src/mzversion.h
system "CRTCPPMOD MODULE(${BUILDLIB}/$*) SRCSTMF('$(CURDIR)/$<') OPTION(*EVENTF) SYSIFCOPT(*IFS64IO) DBGVIEW(*SOURCE) TERASPACE(*YES *TSIFC) STGMDL(*SNGLVL) DTAMDL(*p128) DEFINE(DEBUG_ENABLED) OUTPUT(*PRINT)" > $*.log 2>&1
Expand Down
14 changes: 10 additions & 4 deletions ile/src/manzan.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _MANZAN_H_
#define _MANZAN_H_
#include <stdio.h>
#include <string>

#define BUFSTR(dest, src) \
std::string dest(src, sizeof(src)); \
Expand All @@ -11,23 +12,29 @@
}

#define BUFSTRN(dest, src, len) \
std::string dest(src, len); \
std::string dest = src.substr(0, len); \
{ \
size_t lastChar = dest.find_last_not_of(" "); \
if (lastChar != std::string::npos) \
{ \
dest.erase(1 + lastChar); \
} \
else \
{ \
dest.clear(); \
} \
}

#define ITOA(dest, src) \
char dest[32]; \
sprintf(dest, "%d", src);

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define PUBLISH_MESSAGE_FUNCTION_SIGNATURE const char *_session_id, \
const char *_msgid, \
const char *_msg_type, \
int _msg_severity, \
int _msg_severity, \
const char *_msg_timestamp, \
const char *_job, \
const char *_sending_usrprf, \
Expand Down Expand Up @@ -68,7 +75,6 @@

#define PUBLISH_OTHER_FUNCTION_SIGNATURE const char *_session_id, const char *_event_type


#ifdef __cplusplus
extern "C"
{
Expand Down
33 changes: 19 additions & 14 deletions test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
#include "manzan.h"

// Demonstrate some basic assertions.
TEST(UTILITY, testCreateTrimmedString) {
std::string spaceAtEnd = "hello ";
std::string trimmed0 = createTrimmedString(spaceAtEnd, sizeof(spaceAtEnd));
EXPECT_STREQ(trimmed0.c_str(), "hello");
TEST(UTILITY, testBUFSTRN) {

std::string spaceInMiddle = "hello d";
std::string trimmed1 = createTrimmedString(spaceInMiddle, sizeof(spaceInMiddle));
EXPECT_STREQ(trimmed1.c_str(), "hello d");
std::string spaceAtEnd = "hello ";
BUFSTRN(trimmed0, spaceAtEnd, sizeof(spaceAtEnd));
EXPECT_STREQ(trimmed0.c_str(), "hello");


std::string spaceAtBeginning = " hello";
std::string trimmed2 = createTrimmedString(spaceAtBeginning, sizeof(spaceAtBeginning));
EXPECT_STREQ(trimmed2.c_str(), " hello");
std::string spaceInMiddle = "hello d";
BUFSTRN(trimmed1, spaceInMiddle, sizeof(spaceInMiddle));
EXPECT_STREQ(trimmed1.c_str(), "hello d");

std::string allSpace = " ";
std::string trimmed3 = createTrimmedString(allSpace, sizeof(allSpace));
EXPECT_STREQ(trimmed3.c_str(), "dd");
std::string spaceAtBeginning = " hello";
BUFSTRN(trimmed2, spaceAtBeginning, sizeof(spaceAtBeginning));
EXPECT_STREQ(trimmed2.c_str(), " hello");

std::string allSpace = " ";
BUFSTRN(trimmed3, allSpace, sizeof(allSpace));
EXPECT_STREQ(trimmed3.c_str(), "");

std::string emptyString = "";
BUFSTRN(trimmed4, emptyString, sizeof(emptyString));
EXPECT_STREQ(trimmed4.c_str(), "");


}

0 comments on commit a359886

Please sign in to comment.