Exemple #1
0
//
// SourceTokenizerC::doCommand_ifndef
//
void SourceTokenizerC::doCommand_ifndef(SourceTokenC *)
{
   SourceTokenC::Reference name = getRaw(); doAssert(name, SourceTokenC::TT_NAM);
   doAssert(peekRaw(), SourceTokenC::TT_ENDL);

   addSkip(hasDefine(name->data) || hasMacro(name->data));
}
Exemple #2
0
//
// SourceTokenizerC::get
//
SourceTokenC::Reference SourceTokenizerC::get
(SourceTokenC::TokenType type, std::string const &data)
{
   SourceTokenC::Reference tok = get();
   doAssert(tok, type); doAssert(tok, data);
   return tok;
}
Exemple #3
0
//
// SourceTokenizerC::doCommand_undef
//
void SourceTokenizerC::doCommand_undef(SourceTokenC *)
{
   SourceTokenC::Reference name = getRaw(); doAssert(name, SourceTokenC::TT_NAM);
   doAssert(peekRaw(), SourceTokenC::TT_ENDL);

   if (isSkip()) return;

   remDefine(name->data);
}
Exemple #4
0
//
// SourceTokenizerC::doCommand_define
//
void SourceTokenizerC::doCommand_define(SourceTokenC *)
{
   SourceTokenC::Reference name = getRaw(); doAssert(name, SourceTokenC::TT_NAM);

   if (inStack.back()->peek() == '(')
   {
      MacroData data;

      doAssert(getRaw(), SourceTokenC::TT_PAREN_O);
      SourceTokenC::Reference arg = getRaw();
      if (arg->type != SourceTokenC::TT_PAREN_C) for (;;)
      {
         if (arg->type == SourceTokenC::TT_DOT3)
         {
            data.first.push_back(std::string());
            doAssert((arg = getRaw()), SourceTokenC::TT_PAREN_C);
            break;
         }

         doAssert(arg, SourceTokenC::TT_NAM);
         data.first.push_back(arg->data);

         if ((arg = getRaw())->type == SourceTokenC::TT_PAREN_C) break;
         doAssert(arg, SourceTokenC::TT_COMMA);
         arg = getRaw();
      }

      inStack.back()->disableQuote();
      for (char c; (c = inStack.back()->get()) != '\n';)
         data.second += c;
      inStack.back()->enableQuote();

      inStack.back()->unget('\n');

      if (isSkip()) return;

      addMacro(name->data, data);
   }
   else
   {
      std::string data;

      inStack.back()->disableQuote();
      for (char c; (c = inStack.back()->get()) != '\n';)
         data += c;
      inStack.back()->enableQuote();

      inStack.back()->unget('\n');

      if (isSkip()) return;

      addDefine(name->data, data);
   }
}
Exemple #5
0
//
// SourceTokenizerC::doCommand
//
void SourceTokenizerC::doCommand()
{
   SourceTokenC::Reference tok = getRaw(); doAssert(tok, SourceTokenC::TT_NAM);

        if (tok->data == "define")  doCommand_define(tok);
   else if (tok->data == "else")    doCommand_else(tok);
   else if (tok->data == "elif")    doCommand_elif(tok);
   else if (tok->data == "endif")   doCommand_endif(tok);
   else if (tok->data == "error")   doCommand_error(tok);
   else if (tok->data == "if")      doCommand_if(tok);
   else if (tok->data == "ifdef")   doCommand_ifdef(tok);
   else if (tok->data == "ifndef")  doCommand_ifndef(tok);
   else if (tok->data == "include") doCommand_include(tok);
   else if (tok->data == "undef")   doCommand_undef(tok);
   else if (tok->data == "warning") doCommand_warning(tok);

   else if(isSkip())
   {
      while(tok->type != SourceTokenC::TT_ENDL)
         tok = getRaw();

      unget(tok);
   }
   else Error(tok->pos, "unknown command: %s", tok->data.c_str());
}
Exemple #6
0
bool_t getBoolConf(param_t param)
{
	config_setting_t *setting = NULL;

	switch (param) {
		case ALLOW_TEXTMESSAGE:
			setting = config_lookup(&configuration, "allow_textmessage");
			if (!setting)
				return true;
			else
				return config_setting_get_bool(setting);
			break;
		case ENABLE_BAN:
			setting = config_lookup(&configuration, "enable_ban");
			if (!setting)
				return false;
			else
				return config_setting_get_bool(setting);
			break;
		case SYNC_BANFILE:
			setting = config_lookup(&configuration, "sync_banfile");
			if (!setting)
				return false;
			else
				return config_setting_get_bool(setting);
			break;
		default:
			doAssert(false);
	}
}
Exemple #7
0
const char *getStrConf(param_t param)
{
	switch (param) {
		case CERTIFICATE:
			return "/etc/umurmur/certificate.crt";
		case KEY:
			return "/etc/umurmur/private_key.key";
		case CAPATH:
			return NULL;
		case PASSPHRASE:
			return "";
		case ADMIN_PASSPHRASE:
			return "";
		case WELCOMETEXT:
			return DEFAULT_WELCOME;
		case DEFAULT_CHANNEL:
			return "";
		case BANFILE:
			return NULL;
		default:
			doAssert(false);
			break;
	}
	return NULL;
}
Exemple #8
0
//
// SourceTokenizerC::doCommand_endif
//
void SourceTokenizerC::doCommand_endif(SourceTokenC *tok)
{
   doAssert(peekRaw(), SourceTokenC::TT_ENDL);

   if (skipStack.empty())
      Error(tok->pos, "unmatched #endif");

   remSkip();
}
Exemple #9
0
int getIntConf(param_t param)
{
	config_setting_t *setting = NULL;

	switch (param) {
		case BINDPORT:
			setting = config_lookup(&configuration, "bindport");
			if (!setting)
				return DEFAULT_BINDPORT;
			else {
				return config_setting_get_int(setting);
			}
			break;
		case BINDPORT6:
			setting = config_lookup(&configuration, "bindport6");
			if (!setting)
				return DEFAULT_BINDPORT;
			else {
				return config_setting_get_int(setting);
			}
			break;
		case BAN_LENGTH:
			setting = config_lookup(&configuration, "ban_length");
			if (!setting)
				return DEFAULT_BAN_LENGTH;
			else {
				return config_setting_get_int(setting);
			}
			break;
		case MAX_BANDWIDTH:
			setting = config_lookup(&configuration, "max_bandwidth");
			if (!setting)
				return DEFAULT_MAX_BANDWIDTH;
			else {
				return config_setting_get_int(setting);
			}
			break;
		case MAX_CLIENTS:
			setting = config_lookup(&configuration, "max_users");
			if (!setting)
				return DEFAULT_MAX_CLIENTS;
			else {
				return config_setting_get_int(setting);
			}
			break;
		case OPUS_THRESHOLD:
			setting = config_lookup(&configuration, "opus_threshold");
			if (!setting)
				return DEFAULT_OPUS_THRESHOLD;
			else {
				return config_setting_get_int(setting);
			}
			break;
		default:
			doAssert(false);
	}
}
Exemple #10
0
//
// SourceTokenizerC::doCommand_else
//
void SourceTokenizerC::doCommand_else(SourceTokenC *tok)
{
   doAssert(peekRaw(), SourceTokenC::TT_ENDL);

   if (skipStack.empty())
      Error(tok->pos, "unmatched #else");

   skipStack.back() = unskipStack.back();
   unskipStack.back() = true; // If it wasn't, it is now.
}
Exemple #11
0
//
// SourceTokenizerC::doCommand_elif
//
void SourceTokenizerC::doCommand_elif(SourceTokenC *tok)
{
   if (skipStack.empty())
      Error(tok->pos, "unmatched #elif");

   bool ifResult = !!getExpr()->resolveINT();
   doAssert(peekRaw(), SourceTokenC::TT_ENDL);

     skipStack.back() = unskipStack.back() || !ifResult;
   unskipStack.back() = unskipStack.back() ||  ifResult;
}
Exemple #12
0
int getIntConf(param_t param)
{
	switch (param) {
		case BAN_LENGTH:
			return DEFAULT_BAN_LENGTH;
		case MAX_BANDWIDTH:
			return DEFAULT_MAX_BANDWIDTH;
		case MAX_CLIENTS:
			return DEFAULT_MAX_CLIENTS;
		case OPUS_THRESHOLD:
			return DEFAULT_OPUS_THRESHOLD;
		default:
			doAssert(false);
	}

	assert(false);
	return 0;
}
Exemple #13
0
bool_t getBoolConf(param_t param)
{
	switch (param) {
		case ALLOW_TEXTMESSAGE:
			return true;
		case ENABLE_BAN:
			return false;
		case SYNC_BANFILE:
			return false;
		case SHOW_ADDRESSES:
			return true;
		default:
			doAssert(false);
	}

	assert(false);
	return false;
}
Exemple #14
0
//
// SourceTokenizerC::doCommand_include
//
void SourceTokenizerC::doCommand_include(SourceTokenC *)
{
   SourceTokenC::Reference inc = getRaw();
   std::string filename;
   unsigned flags = SourceStream::ST_C;

   if(inc->type == SourceTokenC::TT_STR)
      filename = inc->data;
   else if(inc->type == SourceTokenC::TT_CMP_LT)
   {
      flags |= SourceStream::STF_NOUSER;

      for(char c; (c = inStack.back()->get()) != '>';)
      {
         if(c == '\n') Error(inc->pos, "unterminated include");
         filename += c;
      }
   }
   else
      Error(inc->pos, "expected TT_STR or TT_CMP_LT");

   doAssert(peekRaw(), SourceTokenC::TT_ENDL);

   if (isSkip()) return;

   try
   {
      inStack.push_back(new SourceStream(filename, flags));
      ungetStack.push_back(static_cast<SourceTokenC::Reference>(
         new SourceTokenC(SourcePosition::builtin(), SourceTokenC::TT_ENDL)));
   }
   catch (std::exception const &)
   {
      Error(inc->pos, "file not found: %s", filename.c_str());
   }
}
Exemple #15
0
static void TestPUtilAPI(void){

    double  n1=0.0, y1=0.0, expn1, expy1;
    double  value1 = 0.021;
    char *str=0;
    UBool isTrue=FALSE;

    log_verbose("Testing the API uprv_modf()\n");
    y1 = uprv_modf(value1, &n1);
    expn1=0;
    expy1=0.021;
    if(y1 != expy1   || n1 != expn1){
        log_err("Error in uprv_modf.  Expected IntegralValue=%f, Got=%f, \n Expected FractionalValue=%f, Got=%f\n",
             expn1, n1, expy1, y1);
    }
    if(getTestOption(VERBOSITY_OPTION)){
        log_verbose("[float]  x = %f  n = %f y = %f\n", value1, n1, y1);
    }
    log_verbose("Testing the API uprv_fmod()\n");
    expn1=uprv_fmod(30.50, 15.00);
    doAssert(expn1, 0.5, "uprv_fmod(30.50, 15.00) failed.");

    log_verbose("Testing the API uprv_ceil()\n");
    expn1=uprv_ceil(value1);
    doAssert(expn1, 1, "uprv_ceil(0.021) failed.");

    log_verbose("Testing the API uprv_floor()\n");
    expn1=uprv_floor(value1);
    doAssert(expn1, 0, "uprv_floor(0.021) failed.");

    log_verbose("Testing the API uprv_fabs()\n");
    expn1=uprv_fabs((2.02-1.345));
    doAssert(expn1, 0.675, "uprv_fabs(2.02-1.345) failed.");
    
    log_verbose("Testing the API uprv_fmax()\n");
    doAssert(uprv_fmax(2.4, 1.2), 2.4, "uprv_fmax(2.4, 1.2) failed.");

    log_verbose("Testing the API uprv_fmax() with x value= NaN\n");
    expn1=uprv_fmax(uprv_getNaN(), 1.2);
    doAssert(expn1, uprv_getNaN(), "uprv_fmax(uprv_getNaN(), 1.2) failed. when one parameter is NaN");

    log_verbose("Testing the API uprv_fmin()\n");
    doAssert(uprv_fmin(2.4, 1.2), 1.2, "uprv_fmin(2.4, 1.2) failed.");

    log_verbose("Testing the API uprv_fmin() with x value= NaN\n");
    expn1=uprv_fmin(uprv_getNaN(), 1.2);
    doAssert(expn1, uprv_getNaN(), "uprv_fmin(uprv_getNaN(), 1.2) failed. when one parameter is NaN");

    log_verbose("Testing the API uprv_max()\n");
    doAssert(uprv_max(4, 2), 4, "uprv_max(4, 2) failed.");

    log_verbose("Testing the API uprv_min()\n");
    doAssert(uprv_min(-4, 2), -4, "uprv_min(-4, 2) failed.");

    log_verbose("Testing the API uprv_trunc()\n");
    doAssert(uprv_trunc(12.3456), 12, "uprv_trunc(12.3456) failed.");
    doAssert(uprv_trunc(12.234E2), 1223, "uprv_trunc(12.234E2) failed.");
    doAssert(uprv_trunc(uprv_getNaN()), uprv_getNaN(), "uprv_trunc(uprv_getNaN()) failed. with parameter=NaN");
    doAssert(uprv_trunc(uprv_getInfinity()), uprv_getInfinity(), "uprv_trunc(uprv_getInfinity()) failed. with parameter=Infinity");


    log_verbose("Testing the API uprv_pow10()\n");
    doAssert(uprv_pow10(4), 10000, "uprv_pow10(4) failed.");

    log_verbose("Testing the API uprv_isNegativeInfinity()\n");
    isTrue=uprv_isNegativeInfinity(uprv_getInfinity() * -1);
    if(isTrue != TRUE){
        log_err("ERROR: uprv_isNegativeInfinity failed.\n");
    }
    log_verbose("Testing the API uprv_isPositiveInfinity()\n");
    isTrue=uprv_isPositiveInfinity(uprv_getInfinity());
    if(isTrue != TRUE){
        log_err("ERROR: uprv_isPositiveInfinity failed.\n");
    }
    log_verbose("Testing the API uprv_isInfinite()\n");
    isTrue=uprv_isInfinite(uprv_getInfinity());
    if(isTrue != TRUE){
        log_err("ERROR: uprv_isInfinite failed.\n");
    }

#if 0
    log_verbose("Testing the API uprv_digitsAfterDecimal()....\n");
    doAssert(uprv_digitsAfterDecimal(value1), 3, "uprv_digitsAfterDecimal() failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E-2), 6, "uprv_digitsAfterDecimal(1.2345E-2) failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed.");
    doAssert(uprv_digitsAfterDecimal(-1.2345E-20), 24, "uprv_digitsAfterDecimal(1.2345E-20) failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E20), 0, "uprv_digitsAfterDecimal(1.2345E20) failed.");
    doAssert(uprv_digitsAfterDecimal(-0.021), 3, "uprv_digitsAfterDecimal(-0.021) failed.");
    doAssert(uprv_digitsAfterDecimal(23.0), 0, "uprv_digitsAfterDecimal(23.0) failed.");
    doAssert(uprv_digitsAfterDecimal(0.022223333321), 9, "uprv_digitsAfterDecimal(0.022223333321) failed.");
#endif

    log_verbose("Testing the API u_errorName()...\n");
    str=(char*)u_errorName((UErrorCode)0);
    if(strcmp(str, "U_ZERO_ERROR") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: U_ZERO_ERROR Got=%s\n",  str);
    }
    log_verbose("Testing the API u_errorName()...\n");
    str=(char*)u_errorName((UErrorCode)-127);
    if(strcmp(str, "U_USING_DEFAULT_WARNING") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: U_USING_DEFAULT_WARNING Got=%s\n",  str);
    }
    log_verbose("Testing the API u_errorName().. with BOGUS ERRORCODE...\n");
    str=(char*)u_errorName((UErrorCode)200);
    if(strcmp(str, "[BOGUS UErrorCode]") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: [BOGUS UErrorCode] Got=%s\n",  str);
    }

    {
        const char* dataDirectory;
        int32_t dataDirectoryLen;
        UChar *udataDir=0;
        UChar temp[100];
        char *charvalue=0;
        log_verbose("Testing chars to UChars\n");
        
         /* This cannot really work on a japanese system. u_uastrcpy will have different results than */
        /* u_charsToUChars when there is a backslash in the string! */
        /*dataDirectory=u_getDataDirectory();*/

        dataDirectory="directory1";  /*no backslashes*/
        dataDirectoryLen=(int32_t)strlen(dataDirectory);
        udataDir=(UChar*)malloc(sizeof(UChar) * (dataDirectoryLen + 1));
        u_charsToUChars(dataDirectory, udataDir, (dataDirectoryLen + 1));
        u_uastrcpy(temp, dataDirectory);
       
        if(u_strcmp(temp, udataDir) != 0){
            log_err("ERROR: u_charsToUChars failed. Expected %s, Got %s\n", austrdup(temp), austrdup(udataDir));
        }
        log_verbose("Testing UChars to chars\n");
        charvalue=(char*)malloc(sizeof(char) * (u_strlen(udataDir) + 1));

        u_UCharsToChars(udataDir, charvalue, (u_strlen(udataDir)+1));
        if(strcmp(charvalue, dataDirectory) != 0){
            log_err("ERROR: u_UCharsToChars failed. Expected %s, Got %s\n", charvalue, dataDirectory);
        }
        free(charvalue);
        free(udataDir);
    }
   
    log_verbose("Testing uprv_timezone()....\n");
    {
        int32_t tzoffset = uprv_timezone();
        log_verbose("Value returned from uprv_timezone = %d\n",  tzoffset);
        if (tzoffset != 28800) {
            log_verbose("***** WARNING: If testing in the PST timezone, t_timezone should return 28800! *****");
        }
        if ((tzoffset % 1800 != 0)) {
            log_info("Note: t_timezone offset of %ld (for %s : %s) is not a multiple of 30min.", tzoffset, uprv_tzname(0), uprv_tzname(1));
        }
        /*tzoffset=uprv_getUTCtime();*/

    }
}
Exemple #16
0
//
// SourceTokenizerC::readArgs
//
// Process function-like macro arguments, preserving whitespace in TT_NONEs.
//
void SourceTokenizerC::readArgs(MacroArgs &args, SourceStream *in, MacroData const &data,
   SourcePosition const &pos, MacroArgs const *altArgs, MacroParm const *altParm)
{
   MacroArg const *arg;
   MacroParm const &parm = data.first;
   int pdepth = 0;

   // If there are no arguments expected, then this is just a simple assertion.
   if(parm.empty())
   {
      doAssert(SourceTokenC::create(in), SourceTokenC::TT_PAREN_C);
   }
   // Otherwise, start reading args. Each arg being a vector of tokens.
   // First thing is to create the first vector, though.
   else for(args.push_back(MacroArg());;)
   {
      // Convert each whitespace character into a TT_NONE token.
      // These are used by operator # to add spaces.
      while (std::isspace(in->peek()))
      {
         in->get();
         args.back().push_back(SourceTokenC::tt_none());
      }

      // Read the token.
      SourceTokenC::Reference tok = SourceTokenC::create(in);

      // If it's a parenthesis, terminate on the close-parenthesis that matches
      // the initial one that started the expansion.
      if(tok->type == SourceTokenC::TT_PAREN_O) ++pdepth;
      if(tok->type == SourceTokenC::TT_PAREN_C && !pdepth--) break;

      // A comma not in parentheses starts a new argument...
      if(tok->type == SourceTokenC::TT_COMMA && !pdepth &&
      // ... Unless we've reached the __VA_ARGS__ segment.
         (args.size() < parm.size() || !parm.back().empty()))
      {
         args.push_back(MacroArg());
         continue;
      }

      // If we're being called from a function-like macro expansion and we see
      // one of its arguments, expand it.
      if(tok->type == SourceTokenC::TT_NAM && altArgs && altParm &&
         (arg = find_arg(*altArgs, *altParm, tok->data)))
      {
         for(MacroArg::const_iterator tokEnd = arg->end(),
             tokItr = arg->begin(); tokItr != tokEnd; ++tokItr)
         {
            args.back().push_back(*tokItr);
         }
      }
      else
         args.back().push_back(tok);
   }

   // Must not have empty args.
   for(MacroArgs::iterator argsEnd = args.end(),
       argsItr = args.begin(); argsItr != argsEnd; ++argsItr)
   {
      if(argsItr->empty())
         argsItr->push_back(SourceTokenC::tt_none());
   }

   // And of course, must have the right number of arguments.
   if(args.size() != parm.size())
      Error_P("incorrect arg count for macro, expected %i got %i",
              (int)parm.size(), (int)args.size());
}
Exemple #17
0
//
// SourceTokenizerC::peek
//
SourceTokenC::Reference SourceTokenizerC::peek(SourceTokenC::TokenType type)
{
   SourceTokenC::Reference tok = get(); ungetStack.push_back(tok);
   doAssert(tok, type);
   return tok;
}
Exemple #18
0
const char *getStrConf(param_t param)
{
	config_setting_t *setting = NULL;
	const char *strsetting = NULL;

	switch (param) {
		case CERTIFICATE:
			setting = config_lookup(&configuration, "certificate");
			if (!setting)
				return "/etc/umurmur/certificate.crt";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "/etc/umurmur/certificate.crt";
			}
			break;
		case KEY:
			setting = config_lookup(&configuration, "private_key");
			if (!setting)
				return "/etc/umurmur/private_key.key";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "/etc/umurmur/private_key.key";
			}
			break;
		case CAPATH:
			setting = config_lookup(&configuration, "ca_path");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case PASSPHRASE:
			setting = config_lookup(&configuration, "password");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case ADMIN_PASSPHRASE:
			setting = config_lookup(&configuration, "admin_password");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case BINDADDR:
			setting = config_lookup(&configuration, "bindaddr");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case BINDADDR6:
			setting = config_lookup(&configuration, "bindaddr6");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case WELCOMETEXT:
			setting = config_lookup(&configuration, "welcometext");
			if (!setting)
				return DEFAULT_WELCOME;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return DEFAULT_WELCOME;
			}
			break;
		case DEFAULT_CHANNEL:
			setting = config_lookup(&configuration, "default_channel");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case USERNAME:
			setting = config_lookup(&configuration, "username");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case GROUPNAME:
			setting = config_lookup(&configuration, "groupname");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case LOGFILE:
			setting = config_lookup(&configuration, "logfile");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case BANFILE:
			setting = config_lookup(&configuration, "banfile");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		default:
			doAssert(false);
			break;
	}
	return NULL;
}
Exemple #19
0
//
// SourceTokenizerC::get
//
SourceTokenC::Reference SourceTokenizerC::get(SourceTokenC::TokenType type)
{
   SourceTokenC::Reference tok = get();
   doAssert(tok, type);
   return tok;
}
Exemple #20
0
static void TestPUtilAPI(void){

    double  n1=0.0, y1=0.0, expn1, expy1;
    double  value1 = 0.021;
    UVersionInfo versionArray = {0x01, 0x00, 0x02, 0x02};
    char versionString[17]; /* xxx.xxx.xxx.xxx\0 */
    char *str=0;
    UBool isTrue=FALSE;

    log_verbose("Testing the API uprv_modf()\n");
    y1 = uprv_modf(value1, &n1);
    expn1=0;
    expy1=0.021;
    if(y1 != expy1   || n1 != expn1){
        log_err("Error in uprv_modf.  Expected IntegralValue=%f, Got=%f, \n Expected FractionalValue=%f, Got=%f\n",
             expn1, n1, expy1, y1);
    }
    if(VERBOSITY){
        log_verbose("[float]  x = %f  n = %f y = %f\n", value1, n1, y1);
    }
    log_verbose("Testing the API uprv_fmod()\n");
    expn1=uprv_fmod(30.50, 15.00);
    doAssert(expn1, 0.5, "uprv_fmod(30.50, 15.00) failed.");

    log_verbose("Testing the API uprv_ceil()\n");
    expn1=uprv_ceil(value1);
    doAssert(expn1, 1, "uprv_ceil(0.021) failed.");

    log_verbose("Testing the API uprv_floor()\n");
    expn1=uprv_floor(value1);
    doAssert(expn1, 0, "uprv_floor(0.021) failed.");

    log_verbose("Testing the API uprv_fabs()\n");
    expn1=uprv_fabs((2.02-1.345));
    doAssert(expn1, 0.675, "uprv_fabs(2.02-1.345) failed.");
    
    log_verbose("Testing the API uprv_fmax()\n");
    doAssert(uprv_fmax(2.4, 1.2), 2.4, "uprv_fmax(2.4, 1.2) failed.");

    log_verbose("Testing the API uprv_fmax() with x value= NaN\n");
    expn1=uprv_fmax(uprv_getNaN(), 1.2);
    doAssert(expn1, uprv_getNaN(), "uprv_fmax(uprv_getNaN(), 1.2) failed. when one parameter is NaN");

    log_verbose("Testing the API uprv_fmin()\n");
    doAssert(uprv_fmin(2.4, 1.2), 1.2, "uprv_fmin(2.4, 1.2) failed.");

    log_verbose("Testing the API uprv_fmin() with x value= NaN\n");
    expn1=uprv_fmin(uprv_getNaN(), 1.2);
    doAssert(expn1, uprv_getNaN(), "uprv_fmin(uprv_getNaN(), 1.2) failed. when one parameter is NaN");

    log_verbose("Testing the API uprv_max()\n");
    doAssert(uprv_max(4, 2), 4, "uprv_max(4, 2) failed.");

    log_verbose("Testing the API uprv_min()\n");
    doAssert(uprv_min(-4, 2), -4, "uprv_min(-4, 2) failed.");

    log_verbose("Testing the API uprv_trunc()\n");
    doAssert(uprv_trunc(12.3456), 12, "uprv_trunc(12.3456) failed.");
    doAssert(uprv_trunc(12.234E2), 1223, "uprv_trunc(12.234E2) failed.");
    doAssert(uprv_trunc(uprv_getNaN()), uprv_getNaN(), "uprv_trunc(uprv_getNaN()) failed. with parameter=NaN");
    doAssert(uprv_trunc(uprv_getInfinity()), uprv_getInfinity(), "uprv_trunc(uprv_getInfinity()) failed. with parameter=Infinity");


    log_verbose("Testing the API uprv_pow10()\n");
    doAssert(uprv_pow10(4), 10000, "uprv_pow10(4) failed.");

    log_verbose("Testing the API uprv_log10()\n");
    doAssert(uprv_log10(3456), 3, "uprv_log10(3456) failed.");
#ifdef OS390
    doAssert(uprv_log10(1.0e55), 55, "uprv_log10(1.0e55) failed.");
#else
    doAssert(uprv_log10(1.0e300), 300, "uprv_log10(1.0e300) failed.");
#endif          
    log_verbose("Testing the API uprv_isNegativeInfinity()\n");
    isTrue=uprv_isNegativeInfinity(uprv_getInfinity() * -1);
    if(isTrue != TRUE){
        log_err("ERROR: uprv_isNegativeInfinity failed.\n");
    }
    log_verbose("Testing the API uprv_isPositiveInfinity()\n");
    isTrue=uprv_isPositiveInfinity(uprv_getInfinity());
    if(isTrue != TRUE){
        log_err("ERROR: uprv_isPositiveInfinity failed.\n");
    }
    log_verbose("Testing the API uprv_isInfinite()\n");
    isTrue=uprv_isInfinite(uprv_getInfinity());
    if(isTrue != TRUE){
        log_err("ERROR: uprv_isInfinite failed.\n");
    }

#if 0
    log_verbose("Testing the API uprv_digitsAfterDecimal()....\n");
    doAssert(uprv_digitsAfterDecimal(value1), 3, "uprv_digitsAfterDecimal() failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E-2), 6, "uprv_digitsAfterDecimal(1.2345E-2) failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed.");
    doAssert(uprv_digitsAfterDecimal(-1.2345E-20), 24, "uprv_digitsAfterDecimal(1.2345E-20) failed.");
    doAssert(uprv_digitsAfterDecimal(1.2345E20), 0, "uprv_digitsAfterDecimal(1.2345E20) failed.");
    doAssert(uprv_digitsAfterDecimal(-0.021), 3, "uprv_digitsAfterDecimal(-0.021) failed.");
    doAssert(uprv_digitsAfterDecimal(23.0), 0, "uprv_digitsAfterDecimal(23.0) failed.");
    doAssert(uprv_digitsAfterDecimal(0.022223333321), 9, "uprv_digitsAfterDecimal(0.022223333321) failed.");
#endif


    log_verbose("Testing the API u_versionToString().....\n");
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, "1.0.2.2") != 0){
        log_err("ERROR: u_versionToString() failed. Expected: 1.0.2.2, Got=%s\n", versionString);
    }
    log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n");
    u_versionToString(NULL, versionString);
    if(strcmp(versionString, "") != 0){
        log_err("ERROR: u_versionToString() failed. with versionArray=NULL. It should just return\n");
    }
    log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n");
    u_versionToString(NULL, versionString);
    if(strcmp(versionString, "") != 0){
        log_err("ERROR: u_versionToString() failed . It should just return\n");
    }
    log_verbose("Testing the API u_versionToString().....with versionString=NULL\n");
    u_versionToString(versionArray, NULL);
    if(strcmp(versionString, "") != 0){
        log_err("ERROR: u_versionToString() failed. with versionArray=NULL  It should just return\n");
    }
    versionArray[0] = 0x0a;
    log_verbose("Testing the API u_versionToString().....\n");
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, "10.0.2.2") != 0){
        log_err("ERROR: u_versionToString() failed. Expected: 10.0.2.2, Got=%s\n", versionString);
    }
    versionArray[0] = 0xa0;
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, "160.0.2.2") != 0){
        log_err("ERROR: u_versionToString() failed. Expected: 160.0.2.2, Got=%s\n", versionString);
    }
    versionArray[0] = 0xa0;
    versionArray[1] = 0xa0;
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, "160.160.2.2") != 0){
        log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString);
    }
    versionArray[0] = 0x01;
    versionArray[1] = 0x0a;
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, "1.10.2.2") != 0){
        log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString);
    }

    log_verbose("Testing the API u_versionFromString() ....\n");
    u_versionFromString(versionArray, "1.3.5.6");
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, "1.3.5.6") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n",  versionString);
    }
    log_verbose("Testing the API u_versionFromString() where versionArray=NULL....\n");
    u_versionFromString(NULL, "1.3.5.6");
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, "1.3.5.6") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n",  versionString);
    }

    log_verbose("Testing the API u_getVersion().....\n");
    u_getVersion(versionArray);
    u_versionToString(versionArray, versionString);
    if(strcmp(versionString, U_ICU_VERSION) != 0){
        log_err("ERROR: u_getVersion() failed. Got=%s, expected %s\n",  versionString, U_ICU_VERSION);
    }
    log_verbose("Testing the API u_errorName()...\n");
    str=(char*)u_errorName((UErrorCode)0);
    if(strcmp(str, "U_ZERO_ERROR") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: U_ZERO_ERROR Got=%s\n",  str);
    }
    log_verbose("Testing the API u_errorName()...\n");
    str=(char*)u_errorName((UErrorCode)-127);
    if(strcmp(str, "U_USING_DEFAULT_WARNING") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: U_USING_DEFAULT_WARNING Got=%s\n",  str);
    }
    log_verbose("Testing the API u_errorName().. with BOGUS ERRORCODE...\n");
    str=(char*)u_errorName((UErrorCode)200);
    if(strcmp(str, "[BOGUS UErrorCode]") != 0){
        log_err("ERROR: u_getVersion() failed. Expected: [BOGUS UErrorCode] Got=%s\n",  str);
    }

    {
        const char* dataDirectory;
        UChar *udataDir=0;
        UChar temp[100];
        char *charvalue=0;
        log_verbose("Testing chars to UChars\n");
        
         /* This cannot really work on a japanese system. u_uastrcpy will have different results than */
        /* u_charsToUChars when there is a backslash in the string! */
        /*dataDirectory=u_getDataDirectory();*/

        dataDirectory="directory1";  /*no backslashes*/
        udataDir=(UChar*)malloc(sizeof(UChar) * (strlen(dataDirectory) + 1));
        u_charsToUChars(dataDirectory, udataDir, (strlen(dataDirectory)+1));
        u_uastrcpy(temp, dataDirectory);
       
        if(u_strcmp(temp, udataDir) != 0){
            log_err("ERROR: u_charsToUChars failed. Expected %s, Got %s\n", austrdup(temp), austrdup(udataDir));
        }
        log_verbose("Testing UChars to chars\n");
        charvalue=(char*)malloc(sizeof(char) * (u_strlen(udataDir) + 1));

        u_UCharsToChars(udataDir, charvalue, (u_strlen(udataDir)+1));
        if(strcmp(charvalue, dataDirectory) != 0){
            log_err("ERROR: u_UCharsToChars failed. Expected %s, Got %s\n", charvalue, dataDirectory);
        }
        free(charvalue);
        free(udataDir);
    }
   
    log_verbose("Testing uprv_timezone()....\n");
    {
        int32_t tzoffset = uprv_timezone();
        log_verbose("Value returned from uprv_timezone = %d\n",  tzoffset);
        if (tzoffset != 28800) {
            log_verbose("***** WARNING: If testing in the PST timezone, t_timezone should return 28800! *****");
        }
        if ((tzoffset % 1800 != 0)) {
            log_err("FAIL: t_timezone may be incorrect. It is not a multiple of 30min.");
        }
        tzoffset=uprv_getUTCtime();

    }
}
Exemple #21
0
//
// SourceTokenizerC::doCommand_if
//
void SourceTokenizerC::doCommand_if(SourceTokenC *)
{
   addSkip(!getExpr()->resolveINT());
   doAssert(peekRaw(), SourceTokenC::TT_ENDL);
}
Exemple #22
0
void TestRunner::assert(bool condition, const char *message) {
	doAssert(condition);
	std::cout << message << std::endl;
}