/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// These format strings result in 1024 byte lines on disk regardless // of OS, which makes various file sizes OS-agnostic. #ifdef XP_WIN # define WHOLE_LINE "%01022d\n" # define SHORT_LINE "%0510d\n" #else # define WHOLE_LINE "%01023d\n" # define SHORT_LINE "%0511d\n" #endif
// Write the given number of 1k lines to the given file name. void WriteTestLogFile(constchar* name, uint32_t numLines) {
FILE* f = fopen(name, "w");
ASSERT_NE(f, (FILE*)nullptr);
for (uint32_t i = 0; i < numLines; i++) { char buf[1024 + 1];
SprintfLiteral(buf, WHOLE_LINE, i);
EXPECT_TRUE(fputs(buf, f) >= 0);
}
uint64_t size = static_cast<uint64_t>(ftell(f));
// Close before asserting.
EXPECT_FALSE(fclose(f));
ASSERT_EQ(numLines * 1024, size);
}
// Assert that the given file name has the expected size and that its // first line is the expected line. void AssertSizeAndFirstLine(constchar* name, uint32_t expectedSize, constchar* expectedLine) {
FILE* f = fopen(name, "r");
ASSERT_NE(f, (FILE*)nullptr);
// Here the log file is exactly the allowed size. It shouldn't be limited.
ASSERT_TRUE(
mozilla::detail::LimitFileToLessThanSize(nameBuf, 256 * 1024, 1024));
// Here the log file is strictly less than the allowed size. It shouldn't be // limited.
ASSERT_TRUE(
mozilla::detail::LimitFileToLessThanSize(nameBuf, 256 * 1024, 1024));
// The line to be cut ends "...044\n." We read 512 bytes (the // buffer size), so we're left with 512 bytes, one of which is the // newline.
AssertSizeAndFirstLine(nameBuf, 256 * 1024 - 512, expectedLine);
// We read 512 bytes (the buffer size), so we're left with 512 // bytes, one of which is the newline. Notice that the limited size // is smaller than the requested size.
AssertSizeAndFirstLine(nameBuf, 256 * 1024 - 512, expectedLine);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.