static void GenerateWindow(int widgets, const std::string& filename){

        std::cout << "Loading base files" << std::endl;

        ///
        /// load base files

        // ---------------------------------------------------------------------
        QFile basepre("../window_pre.txt");
        if (!basepre.open(QFile::ReadOnly | QFile::Text)){
            std::cout << "ERROR Loading basepre" << std::endl;
            return;
        }
        QTextStream inpre(&basepre);
        QString basepre_string = inpre.readAll();
        std::cout << "basepre content = " << basepre_string.toStdString() << std::endl;

        // ---------------------------------------------------------------------
        QFile basecore("../window_core.txt");
        if (!basecore.open(QFile::ReadOnly | QFile::Text)){
            std::cout << "ERROR Loading basecore" << std::endl;
            return;
        }
        QTextStream incore(&basecore);
        QString basecore_string = incore.readAll();
        std::cout << "basecore content = " << basecore_string.toStdString() << std::endl;

        // ---------------------------------------------------------------------
        QFile basepost("../window_post.txt");
        if (!basepost.open(QFile::ReadOnly | QFile::Text)){
            std::cout << "ERROR Loading basepost" << std::endl;
            return;
        }
        QTextStream inpost(&basepost);
        QString basepost_string = inpost.readAll();
        std::cout << "basepost content = " << basepost_string.toStdString() << std::endl;

        ///
        /// create window file
        QFile file(filename.c_str());
        if ( file.open(QIODevice::ReadWrite))
        {
            QTextStream stream( &file );
            //
            stream << QString(basepre_string);
            //
            for (int i = 0; i < widgets; i++){
                stream << QString(basecore_string).replace("##widget##",QString::number(i)) << "\n";
            }
            //
            stream << QString(basepost_string);
        }
        file.close();

        std::cout << "done." << std::endl;
    }
bool TestExtServer::test_pagelet_server_task_result() {
    const int TEST_SIZE = 20;

    String baseurl("pageletserver?getparam=");
    String baseheader("MyHeader: ");
    String basepost("postparam=");

    std::vector<Object> tasks;
    for (int i = 0; i < TEST_SIZE; ++i) {
        String url = baseurl + String(i);
        String header = baseheader + String(i);
        String post = basepost + String(i);
        Object task = f_pagelet_server_task_start(url, CREATE_VECTOR1(header),
                      post);
        tasks.push_back(task);
    }

    for (int i = 0; i < TEST_SIZE; ++i) {
        f_pagelet_server_task_status(tasks[i]);
    }

    // Calls that time out (try 1 ms) should return a status code of -1
    for (int i = 0; i < TEST_SIZE; ++i) {
        Variant code, headers;
        VS("", f_pagelet_server_task_result(tasks[i], ref(headers), ref(code), 1));
        VS(code, -1);
    }

    for (int i = 0; i < TEST_SIZE; ++i)  {
        String expected = "pagelet postparam: postparam=";
        expected += String(i);
        expected += "pagelet getparam: ";
        expected += String(i);
        expected += "pagelet header: ";
        expected += String(i);

        // A timeout of 0 indicates an infinite timeout that blocks.
        Variant code, headers;
        VS(expected, f_pagelet_server_task_result(tasks[i], ref(headers),
                ref(code), 0));
        VS(code, 200);
        VS(headers[1], "ResponseHeader: okay");

        VS(expected, f_pagelet_server_task_result(tasks[i], ref(headers),
                ref(code), 1));
        VS(code, 200);
    }

    return Count(true);
}
示例#3
0
bool TestExtServer::test_pagelet_server_task_result() {
  const int TEST_SIZE = 20;

  String baseurl("ext/pageletserver?getparam=");
  String baseheader("MyHeader: ");
  String basepost("postparam=");

  std::vector<Resource> tasks;
  for (int i = 0; i < TEST_SIZE; ++i) {
    String url = baseurl + String(i);
    String header = baseheader + String(i);
    String post = basepost + String(i);
    Resource task = HHVM_FN(pagelet_server_task_start)(url,
      make_packed_array(header), post);
    tasks.push_back(task);
  }

  for (int i = 0; i < TEST_SIZE; ++i) {
    HHVM_FN(pagelet_server_task_status)(tasks[i]);
  }

  // Calls that time out (try 1 ms) should return a status code of -1
  for (int i = 0; i < TEST_SIZE; ++i) {
    Variant code, headers;
    VS("", HHVM_FN(pagelet_server_task_result)(tasks[i], ref(headers),
                                               ref(code), 1));
    VS(code, -1);
  }

  for (int i = 0; i < TEST_SIZE; ++i)  {
    String expected = "pagelet postparam: postparam=";
    expected += String(i);
    expected += "pagelet getparam: ";
    expected += String(i);
    expected += "pagelet header: ";
    expected += String(i);

    // A timeout of 0 indicates an infinite timeout that blocks.
    Variant code, headers;
    VS(expected, HHVM_FN(pagelet_server_task_result)(tasks[i], ref(headers),
                                                     ref(code), 0));
    VS(code, 200);

    Array headerArray = headers.toArray();
    bool hasResponseHeader = false;
    String expectedHeader = String("ResponseHeader: okay");

    for (int headerIdx = 0; headerIdx < headerArray.size(); headerIdx++) {
      if (headerArray[headerIdx].toString() == expectedHeader) {
        hasResponseHeader = true;
        break;
      }
    }
    VERIFY(hasResponseHeader);
    VS(expected, HHVM_FN(pagelet_server_task_result)(tasks[i], ref(headers),
                                                     ref(code), 1));
    VS(code, 200);
  }

  return Count(true);
}