Beispiel #1
0
//
// env [--expandEnv]
//
bool MiscDbugCmd::doEnv(const CmdLine& req)
{
    wchar_t* envW = GetEnvironmentStringsW();
    StringVec env;

    String optK("expandEnv");
    bool expandEnv = Bool(req.opt(optK), false /*defaultV*/);
    DelimitedTxt txt(EQUALS_SIGN);
    String k;
    String kv;
    String v;
    for (const wchar_t* w = envW; *w;)
    {
        kv = w;
        txt.setTxt(kv, false /*makeCopy*/);
        (txt.next(k, true /*doTrimLine*/) && getenv(k, v, expandEnv))?
            env.add(k + EQUALS_SIGN + v):
            env.add(kv);
        size_t n = wcslen(w);
        w += n + 1;
    }

    FreeEnvironmentStringsW(envW);
    env.sort();
    String rsp(env.stringify(NEW_LINE));
    respond(req, rsp);

    bool cmdIsValid = true;
    return cmdIsValid;
}
Beispiel #2
0
void MacAddrSuite::testVec00()
{
    bool ok = true;
    MacAddr macAddr;
    MacAddrVec vec0;
    String mac;
    StringVec macs;
    for (unsigned int i = 0; i < NUM_SAMPLES; ++i)
    {
        const sample_t& r = SAMPLE[i];
        if (r.isValid)
        {
            macAddr = r.addr;
            unsigned int foundAt = vec0.numItems();
            if ((!vec0.add(macAddr)) || (vec0.findIndex(macAddr) != foundAt))
            {
                ok = false;
                break;
            }
            mac = macAddr;
            macs.add(mac);
        }
    }
    CPPUNIT_ASSERT(ok);

    MacAddrVec vec1(vec0);
    ok = (vec1 == vec0);
    CPPUNIT_ASSERT(ok);
    vec1.reset();
    ok = (vec1 != vec0) && (vec1.numItems() == 0);
    CPPUNIT_ASSERT(ok);

    ok = vec1.reset(macs) && (vec1 == vec0);
    CPPUNIT_ASSERT(ok);
    mac = "not-a-mac";
    macs.add(mac);
    ok = (!vec1.reset(macs)) && (vec1 == vec0);
    CPPUNIT_ASSERT(ok);

    bool reverseOrder = false;
    vec0.sort(reverseOrder);
    ok = vec1.find(vec0.peek(0));
    CPPUNIT_ASSERT(ok);
    for (size_t i = 1, numItems = vec0.numItems(); i < numItems; ++i)
    {
        if ((!vec1.find(vec0.peek(i))) || (vec0.peek(i - 1) > vec0.peek(i)))
        {
            ok = false;
            break;
        }
    }
    CPPUNIT_ASSERT(ok);

    reverseOrder = true;
    vec0.sort(reverseOrder);
    ok = vec1.find(vec0.peek(0));
    CPPUNIT_ASSERT(ok);
    for (size_t i = 1, numItems = vec0.numItems(); i < numItems; ++i)
    {
        if ((!vec1.find(vec0.peek(i))) || (vec0.peek(i - 1) < vec0.peek(i)))
        {
            ok = false;
            break;
        }
    }
    CPPUNIT_ASSERT(ok);
}