Exemplo n.º 1
0
bool TestExtMisc::test_token_get_all() {
  String src = "blarb <?php 1";
  VS(f_token_get_all(src),
     CREATE_VECTOR3(CREATE_VECTOR3(k_T_INLINE_HTML, "blarb ", 1),
                    CREATE_VECTOR3(k_T_OPEN_TAG, "<?php ", 1),
                    CREATE_VECTOR3(k_T_LNUMBER, "1", 1)));
  return Count(true);
}
Exemplo n.º 2
0
bool TestExtFb::test_fb_compact_serialize() {
    fb_cs_test(null);
    fb_cs_test(true);
    fb_cs_test(false);
    fb_cs_test(1234.5678);
    fb_cs_test("");
    fb_cs_test("a");
    fb_cs_test("\0");
    fb_cs_test("\0 a");
    fb_cs_test("0123012301230123");
    fb_cs_test("0123012301230123a");
    fb_cs_test("012301230123012");
    fb_cs_test(Array());
    fb_cs_test(CREATE_VECTOR1(12345));
    fb_cs_test(CREATE_VECTOR3(12345,"abc",0.1234));
    fb_cs_test(CREATE_MAP1(1, 12345));
    fb_cs_test(CREATE_MAP3(1, 12345, "a", 123124, "sdf", 0.1234));
    fb_cs_test(CREATE_VECTOR1(CREATE_VECTOR1("a")));
    fb_cs_test(CREATE_VECTOR2(1, CREATE_VECTOR1("a")));
    fb_cs_test(CREATE_VECTOR2(CREATE_VECTOR1("a"), 1));
    fb_cs_test(CREATE_VECTOR2(CREATE_VECTOR1("a"), CREATE_VECTOR1(1)));

    // Test skips
    fb_cs_test(CREATE_MAP3(0, "a", 1, "b", 3, "c"));
    fb_cs_test(CREATE_MAP3(1, "a", 2, "b", 3, "c"));
    fb_cs_test(CREATE_MAP3(0, "a", 2, "b", 3, "c"));
    fb_cs_test(CREATE_MAP1(3, "a"));
    // Test for overflow
    fb_cs_test(CREATE_MAP1((int64_t)((1ULL << 63) - 1), "a"));

    // Test each power of two, +/- 1 and the negatives of them
    // Test a single number and packed inside an array
    for (int i = 0; i < 64; ++i) {
        int64_t n = (1ULL << i);
        fb_cs_test(n);
        fb_cs_test(CREATE_VECTOR1(n));
        fb_cs_test(n-1);
        fb_cs_test(CREATE_VECTOR1(n-1));
        fb_cs_test(n+1);
        fb_cs_test(CREATE_VECTOR1(n+1));
        fb_cs_test(-n);
        fb_cs_test(CREATE_VECTOR1(-n));
        fb_cs_test(-n-1);
        fb_cs_test(CREATE_VECTOR1(-n-1));
        fb_cs_test(-n+1);
        fb_cs_test(CREATE_VECTOR1(-n+1));
    }

    // Test vector code (PHP can't create those, but they might come form
    // C++ code in serialized strings)
    String s("\xfe\x01\x02\x03\xfc");  // VECTOR, 1, 2, 3, STOP
    Variant ret;
    VS(f_fb_compact_unserialize(s, ref(ret)), CREATE_VECTOR3(1, 2, 3));

    return Count(true);
}
Exemplo n.º 3
0
bool TestExtMath::test_min() {
  VS(f_min(4, 2, CREATE_VECTOR4(3, 1, 6, 7)), 1);
  VS(f_min(0, CREATE_VECTOR3(2, 4, 5)), 2);
  VS(f_min(1, 0, CREATE_VECTOR1("hello")), 0);
  VS(f_min(1, "hello", CREATE_VECTOR1(0)), "hello");
  VS(f_min(1, "hello", CREATE_VECTOR1(-1)), -1);
  VS(f_min(1, CREATE_VECTOR3(2, 4, 8),
           CREATE_VECTOR1(CREATE_VECTOR3(2, 5, 1))),
     CREATE_VECTOR3(2, 4, 8));
  VS(f_min(1, "string", CREATE_VECTOR2(CREATE_VECTOR3(2, 5, 7), 42)),
     "string");
  VS(f_min(1, CREATE_MAP1(1, "1236150163")), "1236150163");
  return Count(true);
}
Exemplo n.º 4
0
static void walk_func(VRefParam value, CVarRef key, CVarRef userdata,
                      const void *data) {
  CallCtx* ctx = (CallCtx*)data;
  Variant sink;
  g_vmContext->invokeFunc((TypedValue*)&sink, *ctx,
                          CREATE_VECTOR3(ref(value), key, userdata));
}
Exemplo n.º 5
0
bool TestExtProcess::test_proc_open() {
  Array descriptorspec =
    CREATE_MAP3(0, CREATE_VECTOR2("pipe", "r"),
                1, CREATE_VECTOR2("pipe", "w"),
                2, CREATE_VECTOR3("file", "/tmp/error-output.txt", "a"));
  String cwd = "/tmp";
  Array env = CREATE_MAP1("some_option", "aeiou");

  Variant pipes;
  Variant process = f_proc_open(php_path, descriptorspec, ref(pipes), cwd, env);
  VERIFY(!same(process, false));

  {
    File *f = pipes[0].toObject().getTyped<File>();
    VERIFY(f->valid());
    String s("<?php print(getenv('some_option')); ?>", AttachLiteral);
    f->write(s);
    f->close();
  }
  {
    File *f = pipes[1].toObject().getTyped<File>();
    VERIFY(f->valid());
    StringBuffer sbuf;
    sbuf.read(f);
    f->close();
    VS(sbuf.detach(), "aeiou");
  }

  VS(f_proc_close(process.toObject()), 0);
  return Count(true);
}
Exemplo n.º 6
0
bool TestExtVariable::test_unserialize() {
  {
    // this was crashing
    unserialize_from_string(StringUtil::HexDecode("53203a20224c612072756f74612067697261207065722074757474692220204d203a20227365636f6e646f206d6520736920c3a820696e6361737472617461206461207175616c6368652070617274652122"));
  }
  {
    Variant v = unserialize_from_string("O:8:\"stdClass\":1:{s:4:\"name\";s:5:\"value\";}");
    VERIFY(v.is(KindOfObject));
    Object obj = v.toObject();
    VS(obj->o_getClassName(), "stdClass");
    VS(obj.o_get("name"), "value");
  }
  {
    Variant v = unserialize_from_string(String("O:8:\"stdClass\":1:{s:7:\"\0*\0name\";s:5:\"value\";}", 45, AttachLiteral));
    VERIFY(v.is(KindOfObject));
    Object obj = v.toObject();
    VS(obj->o_getClassName(), "stdClass");
    VS(obj.o_get("name"), uninit_null());
  }
  {
    Variant v1 = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
    Variant v2 = unserialize_from_string("a:3:{s:1:\"a\";s:5:\"apple\";s:1:\"b\";i:2;s:1:\"c\";a:3:{i:0;i:1;i:1;s:1:\"y\";i:2;i:3;}}");
    VS(v1, v2);
  }
  return Count(true);
}
Exemplo n.º 7
0
  static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx) {
    CurlResource *ch = (CurlResource *)ctx;
    ReadHandler *t  = &ch->m_read;

    int length = -1;
    switch (t->method) {
    case PHP_CURL_DIRECT:
      if (!t->fp.isNull()) {
        int data_size = size * nmemb;
        String ret = t->fp->read(data_size);
        length = ret.size();
        if (length) {
          memcpy(data, ret.data(), length);
        }
      }
      break;
    case PHP_CURL_USER:
      {
        int data_size = size * nmemb;
        Variant ret = ch->do_callback(
          t->callback, CREATE_VECTOR3(Object(ch), t->fp->fd(), data_size));
        if (ret.isString()) {
          String sret = ret.toString();
          length = data_size < sret.size() ? data_size : sret.size();
          memcpy(data, sret.data(), length);
        }
        break;
      }
    }
    return length;
  }
Exemplo n.º 8
0
bool TestExtProcess::test_proc_get_status() {
  Array descriptorspec =
    CREATE_MAP3(0, CREATE_VECTOR2("pipe", "r"),
                1, CREATE_VECTOR2("pipe", "w"),
                2, CREATE_VECTOR3("file", "/tmp/error-output.txt", "a"));
  Variant pipes;
  Variant process = f_proc_open("php", descriptorspec, ref(pipes));
  VERIFY(!same(process, false));
  Array ret = f_proc_get_status(process.toObject());
  VS(ret["command"], "php");
  VERIFY(ret["pid"].toInt32() > 0);
  VERIFY(ret["running"]);
  VERIFY(!ret["signaled"]);
  VS(ret["exitcode"], -1);
  VS(ret["termsig"], 0);
  VS(ret["stopsig"], 0);

  {
    File *f = pipes[0].toObject().getTyped<File>();
    VERIFY(f->valid());
    f->close();
  }
  {
    File *f = pipes[1].toObject().getTyped<File>();
    VERIFY(f->valid());
    f->close();
  }
  VS(f_proc_close(process.toObject()), 0);
  return Count(true);
}
Exemplo n.º 9
0
bool TestExtProcess::test_proc_open_env_inh() {
  Array descriptorspec =
    CREATE_MAP3(0, CREATE_VECTOR2("pipe", "r"),
                1, CREATE_VECTOR2("pipe", "w"),
                2, CREATE_VECTOR3("file", "/tmp/error-output.txt", "a"));

  Variant pipes;

  g_context->setenv("inherit_me", "please");
  Variant process = f_proc_open("echo $inherit_me", descriptorspec, ref(pipes));
  VERIFY(!same(process, false));

  {
    File *f = pipes[1].toObject().getTyped<File>();
    VERIFY(f->valid());
    StringBuffer sbuf;
    sbuf.read(f);
    f->close();
    VS(sbuf.detach(), "please\n");
  }

  VS(f_proc_close(process.toObject()), 0);

  // Ensure that PATH makes it through too
  process = f_proc_open("echo $PATH", descriptorspec, ref(pipes));
  VERIFY(!same(process, false));

  {
    File *f = pipes[1].toObject().getTyped<File>();
    VERIFY(f->valid());
    StringBuffer sbuf;
    sbuf.read(f);
    f->close();

    VERIFY(sbuf.length() != 0);
  }

  VS(f_proc_close(process.toObject()), 0);

  // And check that the libc putenv() takes effect, even though we don't
  // want to use that in a threaded environment

  putenv("ZOO=animals");
  process = f_proc_open("echo $ZOO", descriptorspec, ref(pipes));
  VERIFY(!same(process, false));

  {
    File *f = pipes[1].toObject().getTyped<File>();
    VERIFY(f->valid());
    StringBuffer sbuf;
    sbuf.read(f);
    f->close();
    VS(sbuf.detach(), "animals\n");
  }

  VS(f_proc_close(process.toObject()), 0);

  return Count(true);
}
Exemplo n.º 10
0
bool TestExtJson::test_json_decode() {
  Array arr = CREATE_MAP1("fbid", 101501853510151001LL);
  VS(f_json_decode(f_json_encode(arr), true), arr);

  VS(f_json_decode("{\"0\":{\"00\":0}}", true),
     CREATE_MAP1("0", CREATE_MAP1("00", 0)));

  VS(f_json_decode("{\"a\":1,\"b\":2.3,\"3\":\"test\"}", true),
     CREATE_MAP3("a", 1, "b", 2.3, 3, "test"));
  VS(f_json_decode("[\"a\",1,true,false,null]", true),
     CREATE_VECTOR5("a", 1, true, false, null));

  Object obj = f_json_decode("{\"a\":1,\"b\":2.3,\"3\":\"test\"}");
  Object obj2(SystemLib::AllocStdClassObject());
  obj2->o_set("a", 1);
  obj2->o_set("b", 2.3);
  obj2->o_set("3", "test");
  VS(obj.toArray(), obj2.toArray());

  obj = f_json_decode("[\"a\",1,true,false,null]");
  VS(obj.toArray(), CREATE_VECTOR5("a", 1, true, false, null));

  VS(f_json_decode("{z:1}",     true),       null);
  VS(f_json_decode("{z:1}",     true, k_JSON_FB_LOOSE), CREATE_MAP1("z", 1));
  VS(f_json_decode("{z:\"z\"}", true),       null);
  VS(f_json_decode("{z:\"z\"}", true, k_JSON_FB_LOOSE), CREATE_MAP1("z", "z"));
  VS(f_json_decode("{'x':1}",   true),       null);
  VS(f_json_decode("{'x':1}",   true, k_JSON_FB_LOOSE), CREATE_MAP1("x", 1));
  VS(f_json_decode("{y:1,}",    true),       null);
  VS(f_json_decode("{y:1,}",    true, k_JSON_FB_LOOSE), CREATE_MAP1("y", 1));
  VS(f_json_decode("{,}",       true),       null);
  VS(f_json_decode("{,}",       true, k_JSON_FB_LOOSE), null);
  VS(f_json_decode("[1,2,3,]",  true),       null);
  VS(f_json_decode("[1,2,3,]",  true, k_JSON_FB_LOOSE), CREATE_VECTOR3(1,2,3));
  VS(f_json_decode("[,]",       true),       null);
  VS(f_json_decode("[,]",       true, k_JSON_FB_LOOSE), null);
  VS(f_json_decode("[]",        true),       Array::Create());
  VS(f_json_decode("[]",        true, k_JSON_FB_LOOSE), Array::Create());
  VS(f_json_decode("{}",        true),       Array::Create());
  VS(f_json_decode("{}",        true, k_JSON_FB_LOOSE), Array::Create());
  VS(f_json_decode("test",      true),       null);
  VS(f_json_decode("test",      true, k_JSON_FB_LOOSE), "test");
  VS(f_json_decode("'test'",    true),       null);
  VS(f_json_decode("'test'",    true, k_JSON_FB_LOOSE), "test");
  VS(f_json_decode("\"test\"",  true),       "test");
  VS(f_json_decode("\"test\"",  true, k_JSON_FB_LOOSE), "test");

  VS(f_json_decode("[{\"a\":\"apple\"},{\"b\":\"banana\"}]", true),
     CREATE_VECTOR2(CREATE_MAP1("a", "apple"), CREATE_MAP1("b", "banana")));

  Variant a = "[{\"a\":[{\"n\":\"1st\"}]},{\"b\":[{\"n\":\"2nd\"}]}]";
  VS(f_json_decode(a, true),
     CREATE_VECTOR2
     (CREATE_MAP1("a", CREATE_VECTOR1(CREATE_MAP1("n", "1st"))),
      CREATE_MAP1("b", CREATE_VECTOR1(CREATE_MAP1("n", "2nd")))));

  return Count(true);
}
Exemplo n.º 11
0
static void walk_func(VRefParam value, CVarRef key, CVarRef userdata,
                      const void *data) {
  HPHP::VM::CallCtx* ctx = (HPHP::VM::CallCtx*)data;
  Variant sink;
  g_vmContext->invokeFunc((TypedValue*)&sink, ctx->func,
                          CREATE_VECTOR3(ref(value), key, userdata),
                          ctx->this_, ctx->cls,
                          NULL, ctx->invName);
}
Exemplo n.º 12
0
bool TestExtVariable::test_serialize() {
  Object obj(SystemLib::AllocStdClassObject());
  obj->o_set("name", "value");
  VS(f_serialize(obj), "O:8:\"stdClass\":1:{s:4:\"name\";s:5:\"value\";}");

  Variant v = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
  VS(f_serialize(v),
     "a:3:{s:1:\"a\";s:5:\"apple\";s:1:\"b\";i:2;s:1:\"c\";a:3:{i:0;i:1;i:1;s:1:\"y\";i:2;i:3;}}");
  return Count(true);
}
Exemplo n.º 13
0
bool TestExtString::test_strtok() {
  String s = "This is\tan ";
  Array tokens;
  Variant tok = f_strtok(s, " \n\t");
  while (tok) {
    tokens.append(tok);
    tok = f_strtok(" \n\t");
  }
  VS(tokens, CREATE_VECTOR3("This", "is", "an"));
  return Count(true);
}
Exemplo n.º 14
0
bool TestExtString::test_str_replace() {
  {
    VS(f_str_replace("%body%", "black", "<body text='%body%'>"),
       "<body text='black'>");
  }
  {
    Array vowels;
    vowels.append("a");
    vowels.append("e");
    vowels.append("i");
    vowels.append("o");
    vowels.append("u");
    vowels.append("A");
    vowels.append("E");
    vowels.append("I");
    vowels.append("O");
    vowels.append("U");
    VS(f_str_replace(vowels, "", "Hello World of PHP"), "Hll Wrld f PHP");
  }
  {
    String phrase  = "You should eat fruits, vegetables, and fiber every day.";
    Array healthy = CREATE_VECTOR3("fruits", "vegetables", "fiber");
    Array yummy   = CREATE_VECTOR3("pizza", "beer", "ice cream");
    VS(f_str_replace(healthy, yummy, phrase),
       "You should eat pizza, beer, and ice cream every day.");
  }
  {
    Variant count;
    Variant str = f_str_replace("ll", "", "good golly miss molly!",
                                ref(count));
    VS(count, 2);
  }
  {
    Array letters = CREATE_VECTOR2("a", "p");
    Array fruit = CREATE_VECTOR2("apple", "pear");
    String text = "a p";
    VS(f_str_replace(letters, fruit, text), "apearpearle pear");
  }

  return Count(true);
}
Exemplo n.º 15
0
bool TestExtProcess::test_proc_terminate() {
  Array descriptorspec =
    CREATE_MAP3(0, CREATE_VECTOR2("pipe", "r"),
                1, CREATE_VECTOR2("pipe", "w"),
                2, CREATE_VECTOR3("file", "/tmp/error-output.txt", "a"));
  Variant pipes;
  Variant process = f_proc_open(php_path, descriptorspec, ref(pipes));
  VERIFY(!same(process, false));
  VERIFY(f_proc_terminate(process.toObject()));
  // still need to close it, not to leave a zombie behind
  f_proc_close(process.toObject());
  return Count(true);
}
Exemplo n.º 16
0
bool TestExtJson::test_json_encode() {
  VS(f_json_encode(CREATE_MAP3("a", 1, "b", 2.3, 3, "test")),
     "{\"a\":1,\"b\":2.3,\"3\":\"test\"}");
  VS(f_json_encode(CREATE_VECTOR5("a", 1, true, false, uninit_null())),
     "[\"a\",1,true,false,null]");

  VS(f_json_encode("a\xE0"), "null");
  VS(f_json_encode("a\xE0", k_JSON_FB_LOOSE), "\"a?\"");

  VS(f_json_encode(CREATE_MAP2("0", "apple", "1", "banana")),
     "[\"apple\",\"banana\"]");

  VS(f_json_encode(CREATE_VECTOR1(CREATE_MAP1("a", "apple"))),
     "[{\"a\":\"apple\"}]");

  VS(f_json_encode(CREATE_VECTOR1(CREATE_MAP1("a", "apple")),
                   k_JSON_PRETTY_PRINT),
    "[\n    {\n        \"a\": \"apple\"\n    }\n]");

  VS(f_json_encode(CREATE_VECTOR4(1, 2, 3, CREATE_VECTOR3(1, 2, 3)),
                   k_JSON_PRETTY_PRINT),
    "[\n"
    "    1,\n"
    "    2,\n"
    "    3,\n"
    "    [\n"
    "        1,\n"
    "        2,\n"
    "        3\n"
    "    ]\n"
    "]");

  Array arr = CREATE_MAP3(
    "a", 1,
    "b", CREATE_VECTOR2(1, 2),
    "c", CREATE_MAP1("d", 42)
  );
  VS(f_json_encode(arr, k_JSON_PRETTY_PRINT),
    "{\n"
    "    \"a\": 1,\n"
    "    \"b\": [\n"
    "        1,\n"
    "        2\n"
    "    ],\n"
    "    \"c\": {\n"
    "        \"d\": 42\n"
    "    }\n"
    "}");

  return Count(true);
}
bool TestExtVariable::test_var_export() {
  {
    Variant v = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
    VS(f_var_export(v, true),
       "array (\n"
       "  'a' => 'apple',\n"
       "  'b' => 2,\n"
       "  'c' => \n"
       "  array (\n"
       "    0 => 1,\n"
       "    1 => 'y',\n"
       "    2 => 3,\n"
       "  ),\n"
       ")");
  }
  {
    String current_locale = f_setlocale(2, k_LC_ALL, "0");
    if (f_setlocale(2, k_LC_ALL, CREATE_VECTOR5("de","de_DE","de_DE.ISO8859-1","de_DE.ISO_8859-1","de_DE.UTF-8"))) {
      Variant v = CREATE_MAP3("a", -1, "b", 10.5, "c", 5.6);
      VS(f_var_export(v, true),
         "array (\n"
         "  'a' => -1,\n"
         "  'b' => 10.5,\n"
         "  'c' => 5.6,\n"
         ")");
      f_setlocale(2, k_LC_ALL, current_locale);
    } else {
      SKIP("setlocale() failed");
    }
  }
  {
    const char cs[] = "'\0\\";
    const char cr[] = "'\\'' . \"\\0\" . '\\\\'";
    String s(cs, sizeof(cs) - 1, CopyString);
    String r(cr, sizeof(cr) - 1, CopyString);
    VS(f_var_export(s, true), cr);
  }
  {
    Variant v = CREATE_MAP3(String("\0", 1, CopyString), "null",
                            "", "empty",
                            "0", "nul");
    VS(f_var_export(v, true),
       "array (\n"
       "  '' . \"\\0\" . '' => 'null',\n"
       "  '' => 'empty',\n"
       "  0 => 'nul',\n"
       ")");
  }
  return Count(true);
}
Exemplo n.º 18
0
bool TestExtString::test_implode() {
  {
    Array arr = CREATE_VECTOR3("lastname", "email", "phone");
    VS(f_implode(",", arr), "lastname,email,phone");
  }
  {
    Array arr = CREATE_VECTOR3("lastname", "", "phone");
    VS(f_implode(",", arr), "lastname,,phone");
  }
  {
    Array arr = CREATE_VECTOR3("", "email", "phone");
    VS(f_implode(",", arr), ",email,phone");
  }
  {
    Array arr = CREATE_VECTOR3("", "", "");
    VS(f_implode(",", arr), ",,");
  }
  {
    Array arr = Array::Create();
    VS(f_implode(",", arr), "");
  }
  return Count(true);
}
Exemplo n.º 19
0
bool TestExtMb::test_mb_detect_order() {
  String str = "Pr\xC3\x9C\xC3\x9D""fung";

  /* Set detection order by enumerated list */
  {
    f_mb_detect_order("eucjp-win,sjis-win,UTF-8");
    VS(f_mb_detect_encoding(str), "SJIS-win");
    f_mb_detect_order("eucjp-win,UTF-8,sjis-win");
    VS(f_mb_detect_encoding(str), "UTF-8");
  }

  /* Set detection order by array */
  {
    f_mb_detect_order(CREATE_VECTOR3("eucjp-win", "sjis-win", "UTF-8"));
    VS(f_mb_detect_encoding(str), "SJIS-win");
    f_mb_detect_order(CREATE_VECTOR3("eucjp-win", "UTF-8", "sjis-win"));
    VS(f_mb_detect_encoding(str), "UTF-8");
  }

  /* Display current detection order */
  VS(f_implode(", ", f_mb_detect_order()), "eucJP-win, UTF-8, SJIS-win");

  return Count(true);
}
Exemplo n.º 20
0
bool TestExtVariable::test_var_export() {
  Variant v = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
  VS(f_var_export(v, true),
     "array (\n"
     "  'a' => 'apple',\n"
     "  'b' => 2,\n"
     "  'c' => \n"
     "  array (\n"
     "    0 => 1,\n"
     "    1 => 'y',\n"
     "    2 => 3,\n"
     "  ),\n"
     ")");
  return Count(true);
}
Exemplo n.º 21
0
Array f_token_get_all(CStrRef source) {
  Scanner scanner(source.data(), source.size(),
                  Scanner::AllowShortTags | Scanner::ReturnAllTokens);
  ScannerToken tok;
  Location loc;
  int tokid;
  Array res;
  while ((tokid = scanner.getNextToken(tok, loc))) {
    if (tokid < 256) {
      res.append(String::FromChar((char)tokid));
    } else {
      Array p = CREATE_VECTOR3(tokid, String(tok.text()), loc.line0);
      res.append(p);
    }
  }
  return res;
}
Exemplo n.º 22
0
bool TestExtVariable::test_print_r() {
  Variant v = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
  VS(f_print_r(v, true),
     "Array\n"
     "(\n"
     "    [a] => apple\n"
     "    [b] => 2\n"
     "    [c] => Array\n"
     "        (\n"
     "            [0] => 1\n"
     "            [1] => y\n"
     "            [2] => 3\n"
     "        )\n"
     "\n"
     ")\n");
  return Count(true);
}
Exemplo n.º 23
0
bool TestExtMb::test_mb_detect_encoding() {
  String str = "Pr\xC3\x9C\xC3\x9D""fung";

  /* Detect character encoding with current detect_order */
  VS(f_mb_detect_encoding(str), "UTF-8");

  /* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
  VS(f_mb_detect_encoding(str, "auto"), "UTF-8");

  /* Specify encoding_list character encoding by comma separated list */
  VS(f_mb_detect_encoding(str, "JIS, eucjp-win, sjis-win"), "SJIS-win");

  /* Use array to specify encoding_list  */
  Array ary = CREATE_VECTOR3("ASCII", "JIS", "EUC-JP");
  VS(f_mb_detect_encoding(str, ary), "EUC-JP");

  return Count(true);
}
Exemplo n.º 24
0
bool TestExtFb::test_fb_compact_serialize() {
  fb_cs_test(null);
  fb_cs_test(true);
  fb_cs_test(false);
  fb_cs_test(1234.5678);
  fb_cs_test("");
  fb_cs_test("a");
  fb_cs_test("\0");
  fb_cs_test("\0 a");
  fb_cs_test("0123012301230123");
  fb_cs_test("0123012301230123a");
  fb_cs_test("012301230123012");
  fb_cs_test(Array());
  fb_cs_test(CREATE_VECTOR1(12345));
  fb_cs_test(CREATE_VECTOR3(12345,"abc",0.1234));
  fb_cs_test(CREATE_MAP1(1, 12345));
  fb_cs_test(CREATE_MAP3(1, 12345, "a", 123124, "sdf", 0.1234));
  fb_cs_test(CREATE_VECTOR1(CREATE_VECTOR1("a")));
  fb_cs_test(CREATE_VECTOR2(1, CREATE_VECTOR1("a")));
  fb_cs_test(CREATE_VECTOR2(CREATE_VECTOR1("a"), 1));
  fb_cs_test(CREATE_VECTOR2(CREATE_VECTOR1("a"), CREATE_VECTOR1(1)));

  // Test skips
  fb_cs_test(CREATE_MAP3(0, "a", 1, "b", 3, "c"));
  fb_cs_test(CREATE_MAP3(1, "a", 2, "b", 3, "c"));
  fb_cs_test(CREATE_MAP3(0, "a", 2, "b", 3, "c"));
  fb_cs_test(CREATE_MAP1(3, "a"));
  // Test for overflow
  fb_cs_test(CREATE_MAP1((int64)((1ULL << 63) - 1), "a"));

  // Test each power of two, +/- 1 and the negatives of them
  // Test a single number and packed inside an array
  for (int i = 0; i < 64; ++i) {
    int64 n = (1ULL << i);
    fb_cs_test(n);    fb_cs_test(CREATE_VECTOR1(n));
    fb_cs_test(n-1);  fb_cs_test(CREATE_VECTOR1(n-1));
    fb_cs_test(n+1);  fb_cs_test(CREATE_VECTOR1(n+1));
    fb_cs_test(-n);   fb_cs_test(CREATE_VECTOR1(-n));
    fb_cs_test(-n-1); fb_cs_test(CREATE_VECTOR1(-n-1));
    fb_cs_test(-n+1); fb_cs_test(CREATE_VECTOR1(-n+1));
  }
  return Count(true);
}
Exemplo n.º 25
0
bool TestExtProcess::test_proc_get_status() {
  static const StaticString
    s_command("command"),
    s_pid("pid"),
    s_running("running"),
    s_signaled("signaled"),
    s_exitcode("exitcode"),
    s_termsig("termsig"),
    s_stopsig("stopsig");

  Array descriptorspec =
    CREATE_MAP3(0, CREATE_VECTOR2("pipe", "r"),
                1, CREATE_VECTOR2("pipe", "w"),
                2, CREATE_VECTOR3("file", "/tmp/error-output.txt", "a"));
  Variant pipes;
  Variant process = f_proc_open(php_path, descriptorspec, ref(pipes));
  VERIFY(!same(process, false));
  Array ret = f_proc_get_status(process.toObject());
  VS(ret[s_command], php_path);
  VERIFY(ret[s_pid].toInt32() > 0);
  VERIFY(ret[s_running]);
  VERIFY(!ret[s_signaled]);
  VS(ret[s_exitcode], -1);
  VS(ret[s_termsig], 0);
  VS(ret[s_stopsig], 0);

  {
    File *f = pipes[0].toObject().getTyped<File>();
    VERIFY(f->valid());
    f->close();
  }
  {
    File *f = pipes[1].toObject().getTyped<File>();
    VERIFY(f->valid());
    f->close();
  }
  VS(f_proc_close(process.toObject()), 0);
  return Count(true);
}
Exemplo n.º 26
0
bool TestExtVariable::test_unserialize() {
  {
    Variant v = f_unserialize("O:8:\"stdClass\":1:{s:4:\"name\";s:5:\"value\";}");
    VERIFY(v.is(KindOfObject));
    Object obj = v.toObject();
    VS(obj->o_getClassName(), "stdClass");
    VS(obj.o_get("name"), "value");
  }
  {
    Variant v = f_unserialize(String("O:8:\"stdClass\":1:{s:7:\"\0*\0name\";s:5:\"value\";}", 45, AttachLiteral));
    VERIFY(v.is(KindOfObject));
    Object obj = v.toObject();
    VS(obj->o_getClassName(), "stdClass");
    VS(obj.o_get("name"), "value");
  }
  {
    Variant v1 = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
    Variant v2 = f_unserialize("a:3:{s:1:\"a\";s:5:\"apple\";s:1:\"b\";i:2;s:1:\"c\";a:3:{i:0;i:1;i:1;s:1:\"y\";i:2;i:3;}}");
    VS(v1, v2);
  }
  return Count(true);
}
Exemplo n.º 27
0
bool TestExtProcess::test_proc_open_env_inh() {
    Array descriptorspec =
        CREATE_MAP3(0, CREATE_VECTOR2("pipe", "r"),
                    1, CREATE_VECTOR2("pipe", "w"),
                    2, CREATE_VECTOR3("file", "/tmp/error-output.txt", "a"));

    Variant pipes;
    g_context->setenv("inherit_me", "please");
    Variant process = f_proc_open("echo $inherit_me", descriptorspec, ref(pipes));
    VERIFY(!same(process, false));

    {
        File *f = pipes[1].toObject().getTyped<File>();
        VERIFY(f->valid());
        StringBuffer sbuf;
        sbuf.read(f);
        f->close();
        VS(sbuf.detach(), "please\n");
    }

    VS(f_proc_close(process.toObject()), 0);

    return Count(true);
}
Exemplo n.º 28
0
bool TestExtApc::test_apc_store() {
  Array complexMap = CREATE_MAP2("a",
                                 CREATE_MAP2("b", 1, "c",
                                             CREATE_VECTOR2("d", "e")),
                                 "f", CREATE_VECTOR3(1,2,3));
  f_apc_store("complexMap", complexMap);
  f_apc_store("ts", "TestString");
  f_apc_store("ta", CREATE_MAP2("a", 1, "b", 2));
  f_apc_store("ts", "NewValue");
  f_apc_store("ta", CREATE_VECTOR1("newelement"));
  VS(f_apc_fetch("ts"), "NewValue");
  VS(f_apc_fetch("ta"), CREATE_VECTOR1("newelement"));
  VS(f_apc_fetch("complexMap"), complexMap);

  VS(f_apc_fetch("ts"), "NewValue");
  VS(f_apc_fetch("ta"), CREATE_VECTOR1("newelement"));
  VS(f_apc_fetch("complexMap"), complexMap);

  // Make sure it doesn't change the shared value.
  Array complexMapFetched = f_apc_fetch("complexMap");
  VERIFY(complexMapFetched.exists("a"));
  complexMapFetched.set("q",0);
  VERIFY(complexMapFetched.exists("q"));
  VS(f_apc_fetch("complexMap"), complexMap);

  String tsFetched = f_apc_fetch("ts");
  VS(tsFetched, "NewValue");
  String sharedString = tsFetched;
  tsFetched.lvalAt(0) = "M";
  VS(tsFetched, "MewValue");
  VS(sharedString, "NewValue");
  VERIFY(tsFetched.get() != sharedString.get());
  VS(f_apc_fetch("ts"), "NewValue");

  return Count(true);
}
Exemplo n.º 29
0
bool TestExtVariable::test_debug_zval_dump() {
  Variant v = CREATE_MAP3("a","apple","b",2,"c",CREATE_VECTOR3(1,"y",3));
  g_context->obStart();
  f_debug_zval_dump(v);
  String output = g_context->obCopyContents();
  g_context->obEnd();
  VS(output,
     "array(3) refcount(1){\n"
     "  [\"a\"]=>\n"
     "  string(5) \"apple\" refcount(1)\n"
     "  [\"b\"]=>\n"
     "  long(2) refcount(1)\n"
     "  [\"c\"]=>\n"
     "  array(3) refcount(1){\n"
     "    [0]=>\n"
     "    long(1) refcount(1)\n"
     "    [1]=>\n"
     "    string(1) \"y\" refcount(1)\n"
     "    [2]=>\n"
     "    long(3) refcount(1)\n"
     "  }\n"
     "}\n");
  return Count(true);
}
Exemplo n.º 30
0
Array f_sys_getloadavg() {
  double load[3];
  getloadavg(load, 3);
  return CREATE_VECTOR3(load[0], load[1], load[2]);
}