string longestPalindrome(string s) {
        res = "";
        int n = s.size();

        for (int i = 0; i < n; i++) {
            longString(s, i, i);
            if (i > 0)
                longString(s, i - 1, i);
        }

        return res;
    }
TEST(liblog, too_big_payload) {
    pid_t pid = getpid();
    static const char big_payload_tag[] = "TEST_big_payload_XXXX";
    char tag[sizeof(big_payload_tag)];
    memcpy(tag, big_payload_tag, sizeof(tag));
    snprintf(tag + sizeof(tag) - 5, 5, "%04X", pid & 0xFFFF);

    std::string longString(3266519, 'x');

    ssize_t ret = LOG_FAILURE_RETRY(__android_log_buf_write(LOG_ID_SYSTEM,
                                    ANDROID_LOG_INFO, tag, longString.c_str()));

    struct logger_list *logger_list;

    ASSERT_TRUE(NULL != (logger_list = android_logger_list_open(
        LOG_ID_SYSTEM, O_RDONLY | O_NDELAY, 100, 0)));

    ssize_t max_len = 0;

    for(;;) {
        log_msg log_msg;
        if (android_logger_list_read(logger_list, &log_msg) <= 0) {
            break;
        }

        if ((log_msg.entry.pid != pid) || (log_msg.id() != LOG_ID_SYSTEM)) {
            continue;
        }

        char *data = log_msg.msg() + 1;

        if (strcmp(data, tag)) {
            continue;
        }

        data += strlen(data) + 1;

        const char *left = data;
        const char *right = longString.c_str();
        while (*left && *right && (*left == *right)) {
            ++left;
            ++right;
        }

        if (max_len <= (left - data)) {
            max_len = left - data + 1;
        }
    }

    android_logger_list_close(logger_list);

    EXPECT_LE(LOGGER_ENTRY_MAX_PAYLOAD - sizeof(big_payload_tag),
              static_cast<size_t>(max_len));

    EXPECT_EQ(ret, max_len + sizeof(big_payload_tag));
}
Пример #3
0
void testLongStringConstructor() {
    std::chrono::time_point<std::chrono::system_clock> start, end;
    std::chrono::duration<double> elapsed_time;
    start = std::chrono::system_clock::now();
    BigInt longString("12345678998765432101234567899876543210");
    end = std::chrono::system_clock::now();
    elapsed_time = end - start;
#ifdef _PRINT_VALS
    std::cout<< "longString took: " << elapsed_time.count() << " computing " << longString << std::endl;
#endif
    std::vector<limb_t> actual{1246595009,748116907,1035237483,1632488170};
    std::cout << "String Constructor Correct? " << testEquals(longString, actual) << std::endl;   
}
Пример #4
0
void testVeryLongStringConstructor() {
    std::chrono::time_point<std::chrono::system_clock> start, end;
    std::chrono::duration<double> elapsed_time;
    start = std::chrono::system_clock::now();
    BigInt longString(
#include "bignum.txt"
    );
    end = std::chrono::system_clock::now();
    elapsed_time = end - start;
#ifdef _PRINT_VALS
    std::cout<< "VeryLongString took: " << elapsed_time.count() << " computing " << longString << std::endl;
#endif
    std::vector<limb_t> actual{ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    std::cout << "Very-long String Constructor Correct? " << testEquals(longString, actual) << std::endl;   

}
Пример #5
0
void tst_QVersitWriter::testWritingDocument_data()
{
    QTest::addColumn<QVersitDocument>("document");
    QTest::addColumn<QByteArray>("expected");

    QVersitDocument document(QVersitDocument::VCard21Type);
    document.setComponentType(QStringLiteral("VCARD"));
    QVersitProperty property;
    property.setName(QStringLiteral("FN"));
    property.setValue(QStringLiteral("Bob"));
    document.addProperty(property);
    QTest::newRow("basic vCard 2.1") << document << QByteArray(
            "BEGIN:VCARD\r\n"
            "VERSION:2.1\r\n"
            "FN:Bob\r\n"
            "END:VCARD\r\n"
            );

    document.setComponentType(QStringLiteral("VCARD"));
    document.setType(QVersitDocument::VCard30Type);
    QTest::newRow("basic vCard 3.0") << document << QByteArray(
            "BEGIN:VCARD\r\n"
            "VERSION:3.0\r\n"
            "FN:Bob\r\n"
            "END:VCARD\r\n"
            );

    document.setComponentType(QStringLiteral("VCARD"));
    document.setType(QVersitDocument::VCard40Type);
    QTest::newRow("basic vCard 4.0") << document << QByteArray(
            "BEGIN:VCARD\r\n"
            "VERSION:4.0\r\n"
            "FN:Bob\r\n"
            "END:VCARD\r\n"
            );
    
    {
        QVersitDocument document(QVersitDocument::ICalendar20Type);
        document.setComponentType(QStringLiteral("VCALENDAR"));
        QVersitDocument subdocument(QVersitDocument::ICalendar20Type);
        subdocument.setComponentType(QStringLiteral("VEVENT"));
        property.setValueType(QVersitProperty::PreformattedType);
        property.setName(QStringLiteral("RRULE"));
        property.setValue(QStringLiteral("FREQ=MONTHLY;BYMONTHDAY=1,3"));
        subdocument.addProperty(property);
        document.addSubDocument(subdocument);
        QTest::newRow("basic iCalendar 2.0") << document << QByteArray(
                "BEGIN:VCALENDAR\r\n"
                "VERSION:2.0\r\n"
                "BEGIN:VEVENT\r\n"
                "RRULE:FREQ=MONTHLY;BYMONTHDAY=1,3\r\n"
                "END:VEVENT\r\n"
                "END:VCALENDAR\r\n");
    }

    {
        QVersitDocument document(QVersitDocument::ICalendar20Type);
        document.setComponentType(QStringLiteral("VCALENDAR"));
        QVersitProperty property;
        property.setName(QStringLiteral("PRODID"));
        property.setValue(QStringLiteral("-//hacksw/handcal//NONSGML v1.0//EN"));
        document.addProperty(property);
        QVersitDocument nested(QVersitDocument::ICalendar20Type);
        nested.setComponentType(QStringLiteral("VEVENT"));
        property.setName(QStringLiteral("DTSTART"));
        property.setValue(QStringLiteral("19970714T170000Z"));
        nested.addProperty(property);
        property.setName(QStringLiteral("DTEND"));
        property.setValue(QStringLiteral("19970715T035959Z"));
        nested.addProperty(property);
        property.setName(QStringLiteral("SUMMARY"));
        property.setValue(QStringLiteral("Bastille Day Party"));
        nested.addProperty(property);
        document.addSubDocument(nested);
        QTest::newRow("iCalendar 2.0 from spec") << document << QByteArray(
                        "BEGIN:VCALENDAR\r\n"
                        "VERSION:2.0\r\n"
                        "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"
                        "BEGIN:VEVENT\r\n"
                        "DTSTART:19970714T170000Z\r\n"
                        "DTEND:19970715T035959Z\r\n"
                        "SUMMARY:Bastille Day Party\r\n"
                        "END:VEVENT\r\n"
                        "END:VCALENDAR\r\n");
    }

    {
        QString longString(QLatin1String(
            "4567890123456789012345678901234567890123456789012345678901234567890123456"
            "234567890123456789012345678901234567890123456789012345678901234567890123456"
            "234567890123456789012"));
        QVersitDocument document(QVersitDocument::VCard21Type);
        document.setComponentType(QStringLiteral("VCARD"));
        QVersitProperty property;
        property.setName(QStringLiteral("FN"));
        property.setValue(longString);
        document.addProperty(property);
        QByteArray expected21(
                "BEGIN:VCARD\r\n"
                "VERSION:2.1\r\n"
                "FN:4567890123456789012345678901234567890123456789012345678901234567890123456\r\n"
                " 234567890123456789012345678901234567890123456789012345678901234567890123456\r\n"
                " 234567890123456789012\r\n"
                "END:VCARD\r\n");
        QTest::newRow("folding 2.1") << document << expected21;

        document.setType(QVersitDocument::VCard30Type);
        QByteArray expected30(
                "BEGIN:VCARD\r\n"
                "VERSION:3.0\r\n"
                "FN:4567890123456789012345678901234567890123456789012345678901234567890123456\r\n"
                " 234567890123456789012345678901234567890123456789012345678901234567890123456\r\n"
                " 234567890123456789012\r\n"
                "END:VCARD\r\n");
        QTest::newRow("folding 3.0") << document << expected30;

        document.setType(QVersitDocument::VCard21Type);
        property.setValue(longString.toLatin1());
        property.setValueType(QVersitProperty::BinaryType);
        document.removeProperties("FN");
        document.addProperty(property);
        QByteArray expected21b(
                "BEGIN:VCARD\r\n"
                "VERSION:2.1\r\n"
                "FN;ENCODING=BASE64:\r\n"
                " NDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODk\r\n"
                " wMTIzNDU2Nzg5MDEyMzQ1NjIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MD\r\n"
                " EyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1NjIzNDU2Nzg5MDEyMzQ1Njc4OTAxM\r\n"
                " g==\r\n"
                "\r\n"
                "END:VCARD\r\n");
        QTest::newRow("folding 2.1") << document << expected21b;

        document.setType(QVersitDocument::VCard30Type);
        QByteArray expected30b(
                "BEGIN:VCARD\r\n"
                "VERSION:3.0\r\n"
                "FN;ENCODING=b:NDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OT\r\n"
                " AxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1NjIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwM\r\n"
                " TIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1NjIzNDU2Nzg5MDEy\r\n"
                " MzQ1Njc4OTAxMg==\r\n"
                "END:VCARD\r\n");
        QTest::newRow("folding 3.0") << document << expected30b;
    }
}