コード例 #1
0
ファイル: ut_AString_Utility.cpp プロジェクト: achacha/AOS
void testJustify(int& iRet)
{
  AString str;
  str.assign("2f8");
  str.justifyRight(4, '0');
  ASSERT_UNIT_TEST(str.equals("02f8"), "AString::justifyRight", "0", iRet);
  
  str.justifyRight(8, '0');
  ASSERT_UNIT_TEST(str.equals("000002f8"), "AString::justifyRight", "1", iRet);

  str.justifyRight(3, '0');
  ASSERT_UNIT_TEST(str.equals("000002f8"), "AString::justifyRight", "2", iRet);

  str.assign("2f8");
  str.justifyCenter(8, '0');
  ASSERT_UNIT_TEST(str.equals("0002f800"), "AString::justifyCenter", "0", iRet);

  str.justifyCenter(11, '0');
  ASSERT_UNIT_TEST(str.equals("000002f8000"), "AString::justifyCenter", "1", iRet);

  str.assign("2f8");
  str.justifyCenter(11, '0');
  ASSERT_UNIT_TEST(str.equals("00002f80000"), "AString::justifyCenter", "2", iRet);

  str.justifyCenter(5, '0');
  ASSERT_UNIT_TEST(str.equals("00002f80000"), "AString::justifyCenter", "3", iRet);

  str.assign("2f8");
  str.justifyLeft(7, '0');
  ASSERT_UNIT_TEST(str.equals("2f80000"), "AString::justifyLeft", "0", iRet);

  str.justifyLeft(5, '0');
  ASSERT_UNIT_TEST(str.equals("2f80000"), "AString::justifyLeft", "1", iRet);
}
コード例 #2
0
int ut_ATextConverter_General()
{
  std::cerr << "ut_ATextConverter_General" << std::endl;

  int iRet = 0x0;

  AString result;
  AString str("!<HTML>&...");
  ATextConverter::makeHtmlSafe(str, result);
  ASSERT_UNIT_TEST(result.equals("!&lt;HTML&gt;&amp;..."), "ATextConverter::makeHtmlSafe", "0", iRet);

  result.clear();
  str.assign("<><HTML>&...&");
  ATextConverter::makeHtmlSafe(str, result);
  ASSERT_UNIT_TEST(result.equals("&lt;&gt;&lt;HTML&gt;&amp;...&amp;"), "ATextConverter::makeHtmlSafe", "1", iRet);

  //a_Round trips
  AString strR;
  str = "±(S3t¯th3~co^tro|$~f0r~the~he@rt~of~the¯sµ^!)²÷exit`";
  result.clear();
  ATextConverter::encodeHEX(str, strR);
  ATextConverter::decodeHEX(strR, result);
  ASSERT_UNIT_TEST(result.equals(str), "HEX roudtrip", "", iRet);
  
  strR.clear();
  result.clear();
  ATextConverter::encodeURL(str, strR);
  ATextConverter::decodeURL(strR, result);
  ASSERT_UNIT_TEST(result.equals(str), "URL roudtrip", "", iRet);

  strR.clear();
  result.clear();
  ATextConverter::encodeBase64(str, strR);
  ATextConverter::decodeBase64(strR, result);
  ASSERT_UNIT_TEST(result.equals(str), "Base64 roudtrip", "", iRet);

  strR.clear();
  result.clear();
  ATextConverter::encode64(str, strR);
  ATextConverter::decode64(strR, result);
  ASSERT_UNIT_TEST(result.equals(str), "encode64 roudtrip", "", iRet);

  //a_Base64
  result.clear();
  ATextConverter::encodeBase64("foo:bar", result);
  ASSERT_UNIT_TEST(result.equals("Zm9vOmJhcg=="), "Base64 encode", "", iRet);
  result.clear();
  ATextConverter::decodeBase64("Zm9vOmJhcg==", result);
  ASSERT_UNIT_TEST(result.equals("foo:bar"), "Base64 decode", "", iRet);

  //a_CData safe
  str.assign("!INVALID]]> CData string! ]]> !");
  strR.assign("!INVALID%5d%5d%3e CData string! %5d%5d%3e !");
  result.clear();
  ATextConverter::makeCDataSafe(str, result);
  ASSERT_UNIT_TEST(result.equals(strR), "makeCDataSafe", "", iRet);

  return iRet;
}
コード例 #3
0
int ut_AFragmentString_General(void)
{
  int iRet = 0x0;

  std::cerr << "ut_AFragmentString_General" << std::endl;

	AFragmentString fstr("foo-[1c]\\\\(4,3,1)");
	AString str;
  fstr.next(str);
	int i;
  ASSERT_UNIT_TEST(fstr.getPermutations() == 6, "AFragmentString getPermutations", "0", iRet);

  for (i=0; i<4; ++i) {
		str.clear();
    fstr.next(str);
	}
  ASSERT_UNIT_TEST(str.equals("foo-c\\0002"), "AFragmentString next", "0", iRet);

  //
	fstr.clear();
	fstr.parse("<4>");
  ASSERT_UNIT_TEST(fstr.getPermutations() == 10000, "AFragmentString getPermutations", "1", iRet);

  //
	fstr.clear();
	fstr.parse("(2)");
  ASSERT_UNIT_TEST(fstr.getPermutations() == 100, "AFragmentString getPermutations", "2", iRet);

	//
  fstr.clear();
	fstr.parse("(4,100,112,-3)");
  ASSERT_UNIT_TEST(fstr.getPermutations() == 5, "AFragmentString getPermutations", "3", iRet);
  str.clear();
	fstr.next(str);
  ASSERT_UNIT_TEST(str.equals("0112"), "AFragmentString next", "1", iRet);
	for (i=0; i<2; ++i) {
		str.clear();
    fstr.next(str);
	}
  ASSERT_UNIT_TEST(str.equals("0106"), "AFragmentString next", "2", iRet);
	for (i=0; i<2; ++i) {
		str.clear();
    fstr.next(str);
	}
  ASSERT_UNIT_TEST(str.equals("0100"), "AFragmentString next", "3", iRet);
	
	return iRet;
}
コード例 #4
0
void testSimple(int& iRet)
{
  ANameValuePair nvPair("name", "alex");
  AString str;
  nvPair.emit(str);
  ASSERT_UNIT_TEST(str.equals("name=alex"), "Simple emit to AString failed", "", iRet);
  ASSERT_UNIT_TEST(nvPair.isName("name"), "Checking name", "", iRet);
  ASSERT_UNIT_TEST(nvPair.isValue("alex"), "Checking value", "", iRet);
  ASSERT_UNIT_TEST(!nvPair.isName("Name"), "Checking against wrong case", "", iRet);
  ASSERT_UNIT_TEST(nvPair.isNameNoCase("Name"), "Compare without case", "", iRet);
}
コード例 #5
0
ファイル: ut_AString_Access.cpp プロジェクト: achacha/AOS
int ut_AString_Access()
{
  std::cerr << "ut_AString_Access" << std::endl;

  int iRet = 0x0;

  //a_Peeking
  AString strPeek;
  AString str0 = "SomethingNew";
  str0.peek(strPeek, 0);
  ASSERT_UNIT_TEST(strPeek == "SomethingNew", "AString::peek", "0", iRet);

  strPeek.clear();
  str0.peek(strPeek, 0, 9);
  ASSERT_UNIT_TEST(strPeek == "Something", "AString::peek", "1", iRet);

  strPeek.clear();
  str0.peek(strPeek, 9, 3);
  ASSERT_UNIT_TEST(strPeek == "New", "AString::peek", "2", iRet);
  ASSERT_UNIT_TEST(str0.peek(4) == 't', "AString::peek", "3", iRet);

  int pos0 = 0;
  str0 = "path0/path1/path2";
  strPeek.clear();
  pos0 = str0.peekUntil(strPeek, pos0, '/');
  ASSERT_UNIT_TEST(strPeek.equals("path0"), "AString::peekUntil", "0", iRet);

  strPeek.clear();
  pos0 = str0.peekUntil(strPeek, pos0+1, '/');
  ASSERT_UNIT_TEST(strPeek.equals("path1"), "AString::peekUntil", "1", iRet);

  strPeek.clear();
  pos0 = str0.peekUntil(strPeek, pos0+1, '/');
  ASSERT_UNIT_TEST(strPeek.equals("path2"), "AString::peekUntil", "2", iRet);
  ASSERT_UNIT_TEST(AConstant::npos == pos0, "AString::peekUntil", "3", iRet);

  //a_Set
  AString strSource0 = AString("New"), strSource1("Newer"), strSource2("123Now");
  str0 = "This is old";
  str0.set(strSource0, 8);
  ASSERT_UNIT_TEST(str0.equals("This is New"), "AString::set", "0", iRet);

  str0.set(strSource1, 8);
  ASSERT_UNIT_TEST(str0.equals("This is Newer"), "AString::set", "1", iRet);

  str0.set(strSource2, 8, 3, 3);
  ASSERT_UNIT_TEST(str0.equals("This is Now"), "AString::set", "2", iRet);

  str0.set('n', 8);
  ASSERT_UNIT_TEST(str0.equals("This is now"), "AString::set", "3", iRet);

  //a_Use
  str0.use(10) = 't';
  ASSERT_UNIT_TEST(str0.peek(10) == 't', "AString::use", "0", iRet);

  //a_Get
  AString strGet;
  str0 = "YetMoreStuff!";
  str0.get(strGet, 0, 3);
  ASSERT_UNIT_TEST(strGet.equals("Yet"), "AString::get", "0", iRet);

  str0.get(strGet, 0, 4);
  ASSERT_UNIT_TEST(strGet.equals("More"), "AString::get", "1", iRet);

  str0.get(strGet, 0, 5);
  ASSERT_UNIT_TEST(strGet.equals("Stuff"), "AString::get", "2", iRet);

  str0.get(strGet, 0, 0);
  ASSERT_UNIT_TEST(strGet.isEmpty(), "AString::get", "3", iRet);

  char cX = str0.get();
  ASSERT_UNIT_TEST(cX == '!', "AString::get", "4", iRet);
  ASSERT_UNIT_TEST(strGet.isEmpty(), "AString::get", "5", iRet);

  str0 = "SomeMoreStuff!";
  str0.get(strGet, 0);
  ASSERT_UNIT_TEST(strGet.equals("SomeMoreStuff!"), "AString::get", "6", iRet);
  ASSERT_UNIT_TEST(str0.isEmpty(), "AString::get", "7", iRet);
 
  str0 = "SomeMoreStuff!";
  str0.get(strGet, 0, 0);
  ASSERT_UNIT_TEST(str0.equals("SomeMoreStuff!"), "AString::get", "8", iRet);
  ASSERT_UNIT_TEST(strGet.isEmpty(), "AString::get", "9", iRet);

  str0 = "path0/path1/path2";
  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(strGet.equals("path0"), "AString::getUntil", "0", iRet);

  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(strGet.equals("path1"), "AString::getUntil", "1", iRet);

  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(strGet.equals("path2"), "AString::getUntil", "2", iRet);

  str0.getUntil(strGet, '/');
  ASSERT_UNIT_TEST(str0.isEmpty(), "AString::getUntil", "3", iRet);

  AString str1;
  str0="find_file_1";
  str0.peekUntil(str1, 2, "1");
  ASSERT_UNIT_TEST(!str1.compare("nd_file_"), "AString::peekUntil", "0", iRet);

  str0.getUntil(str1, "_", true);
  ASSERT_UNIT_TEST((!str1.compare("find") && !str0.compare("file_1")), "AString::getUntil", "4", iRet);

  str0="find_file_1";
  str0.getUntilOneOf(str1, ASW("_",1), false);
  ASSERT_UNIT_TEST((!str1.compare("find") && !str0.compare("_file_1")), "AString::getUntil", "5", iRet);

  str0.remove(1);
  str1.clear();
  str0.getUntil(str1, ASW("_",1));
  ASSERT_UNIT_TEST((!str1.compare("file") && !str0.compare("1")), "AString::getUntil", "6", iRet);

  return iRet;
}
コード例 #6
0
int main(int argc, char **argv)
{
  if (argc < 2)
  {
    std::cout << "Usage: this [SQLite database URL]" << std::endl;
    std::cout << "e.g. this sqlite://q:/mydata.db" << std::endl;
    return -1;
  }
  
  AUrl url(argv[1]);
  ASQLiteServer db(url);
  AString error;

  if (!db.init(error))
  {
    std::cerr << error << std::endl;
    return -1;
  }
  
  AString input;
  AFile_IOStream iof;
  std::cout << "\r\nsqlite [?=help]>" << std::flush;
  while(AString::npos != iof.readLine(input))
  {
    if (input.equals("createAOSTables"))
    {
      if (AString::npos == createAOSTables(db, error))
        std::cerr << error << std::endl;
      else
        std::cout << "AOS tables created." << std::endl;
    }
    else if (input.equals("?"))
    {
      std::cout << "Enter SQL query or use one of the following built in functions:\r\n";
      std::cout << "  createAOSTables - create databases used by base AOS server modules\r\n";
      std::cout << std::endl;
    }
    else if (input.equals("exit"))
    {
      return 0;
    }
    else
    {
      AResultSet rs;
      u4 rows = db.executeSQL(input, rs, error);
      if (AString::npos == rows)
      {
        std::cerr << error << std::endl;
        error.clear();
      }
      else
      {
        std::cout << "Success, rows affected=" << rows << std::endl;
        ARope rope;
        rs.emit(rope);
        std::cout << rope << std::endl;
      }
    }
    input.clear();
    std::cout << "\r\nsqlite>" << std::flush;
  }

  return 0;
}
コード例 #7
0
void AOSOutputExecutor::execute(AOSContext& context)
{
  AString command;
  if (
    context.useRequestParameterPairs().exists(OVERRIDE_OUTPUT)
    && m_Services.useConfiguration().isOutputOverrideAllowed()
  )
  {
    //a_Override requested and allowed
    context.useRequestParameterPairs().get(OVERRIDE_OUTPUT, command);
  }
  else
  {
    command = context.getOutputCommand();
    if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
    {
      ARope rope("Default output generator overridden to: ",40);
      rope.append(command);
      context.useEventVisitor().startEvent(rope, AEventVisitor::EL_DEBUG);
    }
  }

  if (command.equals("NOP"))
  {
    //a_If NOP was used force XML
    m_Services.useConfiguration().setMimeTypeFromExt(ASW("xml",3), context);
    if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
      context.useEventVisitor().startEvent(ASWNL("NOP detected, defaulting to XML output"), AEventVisitor::EL_DEBUG);
  }

  if (command.isEmpty())
  {
    if (!m_Services.useConfiguration().getAosDefaultOutputGenerator().isEmpty())
    {
      command.assign(m_Services.useConfiguration().getAosDefaultOutputGenerator());
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
      {
        ARope rope("No output generator specified, defaulting to: ",46);
        rope.append(command);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_DEBUG);
      }
    }
    else
    {
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
        context.useEventVisitor().startEvent(ASW("No output generator, defaulting to XML",38), AEventVisitor::EL_DEBUG);
      return;
    }
  }

  try
  {
    //a_Find input command, if not found execute the default
    OutputGeneratorContainer::iterator it = m_OutputGenerators.find(command);
    if (it == m_OutputGenerators.end())
    {
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_WARN))
      {
        ARope rope("Skipping unknown output generator: ",35);
        rope.append(command);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_WARN);
      }
    }
    else
    {
      ATimer timer(true);

      //a_Generate output
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_INFO))
      {
        ARope rope("Generating output: ",19);
        rope.append((*it).first);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_INFO);
      }

      if (context.useContextFlags().isClear(AOSContext::CTXFLAG_IS_AJAX))
      {
        context.useModel().overwriteElement(ASW("execute/output", 14)).addData(command);

        //a_Publish timers
        context.getRequestTimer().emitXml(context.useModel().overwriteElement(ASW("request_time",12)));
        context.getContextTimer().emitXml(context.useModel().overwriteElement(ASW("context_time",12)));
      }

      //a_Generate output
      AOSContext::ReturnCode ret = (*it).second->execute(context);
      switch (ret)
      {
        case AOSContext::RETURN_OK:
        break;

        case AOSContext::RETURN_REDIRECT:
          if (context.useEventVisitor().isLogging(AEventVisitor::EL_INFO))
          {
            context.useEventVisitor().startEvent(ASWNL("Output generator has done a redirect"), AEventVisitor::EL_DEBUG);
          }
        break;
      
        default:
          context.addError((*it).second->getClass(), ASWNL("Output generator returned neither OK nor REDIRECT"));
        return;
      }

      //a_Event over
      context.useEventVisitor().endEvent();

      //a_Add execution time
      (*it).second->addExecutionTimeSample(timer.getInterval());
    }
  }
  catch(AException& ex)
  {
    AString strWhere("AOSOutputExecutor::execute(", 27);
    strWhere.append(command);
    strWhere.append(')');
    context.addError(strWhere, ex.what());

    AXmlElement& element = context.useModel().addElement("output_error");
    element.addElement("where", strWhere);
    element.addElement("exception", ex);
  }
  catch(...)
  {
    AString strWhere("AOSOutputExecutor::execute(", 27);
    strWhere.append(command);
    strWhere.append(')');
    context.addError(strWhere, ASWNL("Unknown Exception"));

    context.useModel().addElement("output_error").addData("Unknown Exception");
  }
}
コード例 #8
0
void AOSContextManager::adminProcessAction(AXmlElement& eBase, const AHTTPRequestHeader& request)
{
  AString str;
  if (request.getUrl().getParameterPairs().get(ASW("property",8), str))
  {
    if (str.equals(ASWNL("AOSContextManager.log_level")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int level = str.toInt();
        if (level >= AEventVisitor::EL_NONE && level <= AEventVisitor::EL_DEBUG)
        {
          m_DefaultEventLogLevel = level;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid log level, must be (0-5)"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.clear_history")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Clear",5), str))
      {
        int level = str.toInt();
        switch(level)
        {
          case 0:
            _clearHistory();
            _clearErrorHistory();
          break;

          case 1:
            _clearHistory();
          break;

          case 2:
            _clearErrorHistory();
          break;

          default:
            adminAddError(eBase, ASWNL("Invalid level for history clearing, must be (0,1,2)"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.history.max_size")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int i = str.toInt();
        if (i >= 0)
        {
          m_HistoryMaxSize = i;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid maximum size, must be >=0"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.error_history.max_size")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int i = str.toInt();
        if (i >= 0)
        {
          m_ErrorHistoryMaxSize = i;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid maximum size, must be >=0"));
        }
      }
    }
    else if (str.equals(ASWNL("AOSContextManager.freestore.max_size")))
    {
      str.clear();
      if (request.getUrl().getParameterPairs().get(ASW("Set",3), str))
      {
        int i = str.toInt();
        if (i >= 0)
        {
          m_FreeStoreMaxSize = i;
        }
        else
        {
          adminAddError(eBase, ASWNL("Invalid maximum size, must be >=0"));
        }
      }
    }
  }
}