// This C++ source file was generated by the TTCN-3 compiler
// of the TTCN-3 Test Executor version 9.0.0
// The generation of user and time information were disabled by the -D flag.

// Copyright (c) 2000-2023 Ericsson Telecom AB

// Do not edit this file unless you know what you are doing.

/* Including header files */

#include "Misc_Helpers.hh"

namespace Misc__Helpers {

/* Literal string constants */

extern const CHARSTRING cs_1(0, NULL),
cs_4('\n'),
cs_3(3, " : "),
cs_2(':'),
cs_0(7, "nightly");
const unsigned char module_checksum[] = { 0xbf, 0x85, 0xb9, 0x7c, 0xbc, 0x28, 0x37, 0xfc, 0x08, 0x2e, 0x81, 0xf4, 0x0f, 0x04, 0x58, 0x3b };

/* Global variable definitions */

CHARSTRING modulepar_mp__osmo__repo;
const CHARSTRING& mp__osmo__repo = modulepar_mp__osmo__repo;
VERDICTTYPE const_f__shutdown_verdict_defval;
const VERDICTTYPE& f__shutdown_verdict_defval = const_f__shutdown_verdict_defval;
CHARSTRING const_f__shutdown_text_defval;
const CHARSTRING& f__shutdown_text_defval = const_f__shutdown_text_defval;
// No XER for ro__charstring
const TTCN_Typedescriptor_t ro__charstring_descr_ = { "@Misc_Helpers.ro_charstring", NULL, NULL, NULL, NULL, NULL, NULL, NULL, &CHARSTRING_descr_, TTCN_Typedescriptor_t::DONTCARE };
const XERdescriptor_t       ro__charstring_0_xer_ = { {"CHARSTRING>\n", "CHARSTRING>\n"}, {12, 12}, 0 |FORM_UNQUALIFIED, WHITESPACE_PRESERVE,  NULL, &module_object, -1, 0, NULL, NULL, -1, XSD_NONE };
const TTCN_Typedescriptor_t ro__charstring_0_descr_ = { "@Misc_Helpers.ro_charstring.<oftype>", NULL, &CHARSTRING_raw_, &CHARSTRING_text_, &ro__charstring_0_xer_, &CHARSTRING_json_, NULL, NULL, NULL, TTCN_Typedescriptor_t::DONTCARE };
CHARSTRING const_f__str__split_delim_defval;
const CHARSTRING& f__str__split_delim_defval = const_f__str__split_delim_defval;
TTCN_Module module_object("Misc_Helpers", __DATE__, __TIME__, module_checksum, pre_init_module, NULL, 0U, 4294967295U, 4294967295U, 4294967295U, NULL, 0LU, 0, post_init_module, set_module_param, NULL, log_module_param, NULL, NULL, NULL, NULL);

const RuntimeVersionChecker ver_checker(  current_runtime_version.requires_major_version_9,
  current_runtime_version.requires_minor_version_0,
  current_runtime_version.requires_patch_level_0,  current_runtime_version.requires_runtime_1);

/* Bodies of functions, altsteps and testcases */

BOOLEAN f__osmo__repo__is(const CHARSTRING_template& ver)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 19, TTCN_Location::LOCATION_FUNCTION, "f_osmo_repo_is");
current_location.update_lineno(20);
/* Misc_Helpers.ttcn, line 20 */
return ver.match(mp__osmo__repo);
}

void f__shutdown(const CHARSTRING& file, const INTEGER& line, const VERDICTTYPE& verdict, const CHARSTRING& text)
{
CHARSTRING text_shadow(text);
TTCN_Location current_location("Misc_Helpers.ttcn", 31, TTCN_Location::LOCATION_FUNCTION, "f_shutdown");
current_location.update_lineno(33);
/* Misc_Helpers.ttcn, line 33 */
if ((verdict != NONE)) {
current_location.update_lineno(34);
/* Misc_Helpers.ttcn, line 34 */
{
CHARSTRING tmp_0;
tmp_0 = ((((file + cs_2) + int2str(line)) + cs_3) + text_shadow);
text_shadow = tmp_0;
}
current_location.update_lineno(35);
/* Misc_Helpers.ttcn, line 35 */
TTCN_Runtime::setverdict(verdict,(TTCN_Logger::begin_event_log2str(),text_shadow.log(),TTCN_Logger::end_event_log2str()));
}
current_location.update_lineno(38);
/* Misc_Helpers.ttcn, line 38 */
try {
TTCN_Logger::begin_event(TTCN_USER);
TTCN_Logger::log_event_str("Stopping testcase execution from ");
file.log();
TTCN_Logger::log_char(':');
line.log();
TTCN_Logger::end_event();
} catch (...) {
TTCN_Logger::finish_event();
throw;
}
current_location.update_lineno(39);
/* Misc_Helpers.ttcn, line 39 */
if ((self == MTC_COMPREF)) {
current_location.update_lineno(43);
/* Misc_Helpers.ttcn, line 43 */
TTCN_Runtime::stop_component(ALL_COMPREF);
}
current_location.update_lineno(45);
/* Misc_Helpers.ttcn, line 45 */
TTCN_Runtime::stop_component(MTC_COMPREF);
}

BOOLEAN f__addr__is__ipv6(const CHARSTRING& addr)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 48, TTCN_Location::LOCATION_FUNCTION, "f_addr_is_ipv6");
{
current_location.update_lineno(49);
/* Misc_Helpers.ttcn, line 49 */
INTEGER i(0);
current_location.update_lineno(49);
/* Misc_Helpers.ttcn, line 49 */
for ( ; ; ) {
current_location.update_lineno(49);
/* Misc_Helpers.ttcn, line 49 */
if (!(i < addr.lengthof())) break;
current_location.update_lineno(50);
/* Misc_Helpers.ttcn, line 50 */
if ((const_cast< const CHARSTRING&>(addr)[i] == cs_2)) {
current_location.update_lineno(51);
/* Misc_Helpers.ttcn, line 51 */
return TRUE;
}
current_location.update_lineno(49);
/* Misc_Helpers.ttcn, line 49 */
{
INTEGER tmp_1;
++i;
}
}
}
current_location.update_lineno(54);
/* Misc_Helpers.ttcn, line 54 */
return FALSE;
}

OCTETSTRING f__addrstr2addr(const CHARSTRING& addr)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 57, TTCN_Location::LOCATION_FUNCTION, "f_addrstr2addr");
current_location.update_lineno(58);
/* Misc_Helpers.ttcn, line 58 */
if (f__addr__is__ipv6(addr)) {
current_location.update_lineno(59);
/* Misc_Helpers.ttcn, line 59 */
return Native__Functions::f__inet6__addr(addr);
}
else {
current_location.update_lineno(61);
/* Misc_Helpers.ttcn, line 61 */
return Native__Functions::f__inet__addr(addr);
}
}

INTEGER f__strstr__count(const CHARSTRING& str, const CHARSTRING& sub__str)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 66, TTCN_Location::LOCATION_FUNCTION, "f_strstr_count");
current_location.update_lineno(68);
/* Misc_Helpers.ttcn, line 68 */
INTEGER count(0);
current_location.update_lineno(69);
/* Misc_Helpers.ttcn, line 69 */
INTEGER pos(0);
for ( ; ; ) {
current_location.update_lineno(72);
/* Misc_Helpers.ttcn, line 72 */
INTEGER at(TCCConversion__Functions::f__strstr(str, sub__str, pos));
current_location.update_lineno(73);
/* Misc_Helpers.ttcn, line 73 */
if ((at < 0)) {
current_location.update_lineno(74);
/* Misc_Helpers.ttcn, line 74 */
break;
}
current_location.update_lineno(76);
/* Misc_Helpers.ttcn, line 76 */
{
INTEGER tmp_2;
++count;
}
current_location.update_lineno(77);
/* Misc_Helpers.ttcn, line 77 */
pos = (at + 1);
}
current_location.update_lineno(79);
/* Misc_Helpers.ttcn, line 79 */
return count;
}

BOOLEAN f__str__startswith(const CHARSTRING& str, const CHARSTRING& token)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 83, TTCN_Location::LOCATION_FUNCTION, "f_str_startswith");
current_location.update_lineno(85);
/* Misc_Helpers.ttcn, line 85 */
if ((str.lengthof() < token.lengthof())) {
current_location.update_lineno(86);
/* Misc_Helpers.ttcn, line 86 */
return FALSE;
}
current_location.update_lineno(88);
/* Misc_Helpers.ttcn, line 88 */
CHARSTRING str__start(substr(str, 0, token.lengthof()));
current_location.update_lineno(89);
/* Misc_Helpers.ttcn, line 89 */
return (str__start == token);
}

BOOLEAN f__str__endswith(const CHARSTRING& str, const CHARSTRING& token)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 93, TTCN_Location::LOCATION_FUNCTION, "f_str_endswith");
current_location.update_lineno(95);
/* Misc_Helpers.ttcn, line 95 */
if ((str.lengthof() < token.lengthof())) {
current_location.update_lineno(96);
/* Misc_Helpers.ttcn, line 96 */
return FALSE;
}
current_location.update_lineno(98);
/* Misc_Helpers.ttcn, line 98 */
CHARSTRING str__end(substr(str, (str.lengthof() - token.lengthof()), token.lengthof()));
current_location.update_lineno(99);
/* Misc_Helpers.ttcn, line 99 */
return (str__end == token);
}

CHARSTRING f__str__replace(const CHARSTRING& str, const CHARSTRING& find, const CHARSTRING& repl)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 103, TTCN_Location::LOCATION_FUNCTION, "f_str_replace");
current_location.update_lineno(105);
/* Misc_Helpers.ttcn, line 105 */
INTEGER pos(TCCConversion__Functions::f__strstr(str, find, 0));
current_location.update_lineno(106);
/* Misc_Helpers.ttcn, line 106 */
if ((pos < 0)) {
current_location.update_lineno(107);
/* Misc_Helpers.ttcn, line 107 */
return str;
}
current_location.update_lineno(109);
/* Misc_Helpers.ttcn, line 109 */
CHARSTRING prefix(substr(str, 0, pos));
current_location.update_lineno(110);
/* Misc_Helpers.ttcn, line 110 */
INTEGER suffix__pos((pos + find.lengthof()));
current_location.update_lineno(111);
/* Misc_Helpers.ttcn, line 111 */
CHARSTRING suffix(substr(str, suffix__pos, (str.lengthof() - suffix__pos)));
current_location.update_lineno(113);
/* Misc_Helpers.ttcn, line 113 */
CHARSTRING new__str(((prefix + repl) + f__str__replace(suffix, find, repl)));
current_location.update_lineno(114);
/* Misc_Helpers.ttcn, line 114 */
return new__str;
}

ro__charstring f__str__split(const CHARSTRING& str, const CHARSTRING& delim)
{
TTCN_Location current_location("Misc_Helpers.ttcn", 118, TTCN_Location::LOCATION_FUNCTION, "f_str_split");
current_location.update_lineno(120);
/* Misc_Helpers.ttcn, line 120 */
INTEGER pos(0);
current_location.update_lineno(121);
/* Misc_Helpers.ttcn, line 121 */
ro__charstring parts(NULL_VALUE);
current_location.update_lineno(122);
/* Misc_Helpers.ttcn, line 122 */
INTEGER delim__pos;
current_location.update_lineno(123);
/* Misc_Helpers.ttcn, line 123 */
INTEGER end(str.lengthof());
for ( ; ; ) {
current_location.update_lineno(124);
/* Misc_Helpers.ttcn, line 124 */
if (!(pos < end)) break;
current_location.update_lineno(125);
/* Misc_Helpers.ttcn, line 125 */
delim__pos = TCCConversion__Functions::f__strstr(str, delim, pos);
current_location.update_lineno(126);
/* Misc_Helpers.ttcn, line 126 */
if ((delim__pos < 0)) {
current_location.update_lineno(127);
/* Misc_Helpers.ttcn, line 127 */
delim__pos = end;
}
current_location.update_lineno(129);
/* Misc_Helpers.ttcn, line 129 */
if ((delim__pos > pos)) {
current_location.update_lineno(130);
/* Misc_Helpers.ttcn, line 130 */
{
ro__charstring tmp_6;
{
ro__charstring tmp_7;
tmp_7.set_size(1);
tmp_7[0] = substr(str, pos, (delim__pos - pos));
tmp_6 = (parts + tmp_7);
}
parts = tmp_6;
}
}
current_location.update_lineno(132);
/* Misc_Helpers.ttcn, line 132 */
pos = (delim__pos + delim.lengthof());
}
current_location.update_lineno(134);
/* Misc_Helpers.ttcn, line 134 */
return parts;
}


/* Bodies of static functions */

void pre_init_module()
{
TTCN_Location current_location("Misc_Helpers.ttcn", 0, TTCN_Location::LOCATION_UNKNOWN, "Misc_Helpers");
Native__Functions::module_object.pre_init_module();
TCCConversion__Functions::module_object.pre_init_module();
current_location.update_lineno(7);
/* Misc_Helpers.ttcn, line 7 */
modulepar_mp__osmo__repo = cs_0;
module_object.add_modulepar("mp_osmo_repo");
module_object.add_function("f_osmo_repo_is", (genericfunc_t)&f__osmo__repo__is, NULL);
module_object.add_function("f_shutdown", (genericfunc_t)&f__shutdown, NULL);
module_object.add_function("f_addr_is_ipv6", (genericfunc_t)&f__addr__is__ipv6, NULL);
module_object.add_function("f_addrstr2addr", (genericfunc_t)&f__addrstr2addr, NULL);
module_object.add_function("f_strstr_count", (genericfunc_t)&f__strstr__count, NULL);
module_object.add_function("f_str_startswith", (genericfunc_t)&f__str__startswith, NULL);
module_object.add_function("f_str_endswith", (genericfunc_t)&f__str__endswith, NULL);
module_object.add_function("f_str_replace", (genericfunc_t)&f__str__replace, NULL);
module_object.add_function("f_str_split", (genericfunc_t)&f__str__split, NULL);
}

void post_init_module()
{
TTCN_Location current_location("Misc_Helpers.ttcn", 0, TTCN_Location::LOCATION_UNKNOWN, "Misc_Helpers");
Native__Functions::module_object.post_init_module();
TCCConversion__Functions::module_object.post_init_module();
current_location.update_lineno(31);
/* Misc_Helpers.ttcn, line 31 */
const_f__shutdown_verdict_defval = NONE;
current_location.update_lineno(32);
/* Misc_Helpers.ttcn, line 32 */
const_f__shutdown_text_defval = cs_1;
current_location.update_lineno(118);
/* Misc_Helpers.ttcn, line 118 */
const_f__str__split_delim_defval = cs_4;
}

boolean set_module_param(Module_Param& param)
{
const char* const par_name = param.get_id()->get_current_name();
if (!strcmp(par_name, "mp_osmo_repo")) {
modulepar_mp__osmo__repo.set_param(param);
return TRUE;
} else return FALSE;
}

void log_module_param()
{
TTCN_Logger::log_event_str("mp_osmo_repo := ");
mp__osmo__repo.log();
}


} /* end of namespace */
