diff options
author | arthurhsu <arthurhsu@google.com> | 2011-06-27 21:23:55 +0000 |
---|---|---|
committer | arthurhsu <arthurhsu@google.com> | 2011-06-27 21:23:55 +0000 |
commit | fa606d4385cc0cc97f319dc25c97f46b2d44f1b9 (patch) | |
tree | 050f30a499a2715e2de473bdf7cd61063c23a3a7 | |
parent | 95efcd4ba41e367b466b7206a942605bbbbb2c90 (diff) | |
download | sfntly-fa606d4385cc0cc97f319dc25c97f46b2d44f1b9.tar.gz |
Added a preprocessor flag SFNTLY_NO_EXCEPTION to disable exception handling. Fixed the code to make GCC -Wall -Werror flags happy.
-rw-r--r-- | cpp/CMakeLists.txt | 2 | ||||
-rw-r--r-- | cpp/src/sfntly/cmap_table.cc | 2 | ||||
-rw-r--r-- | cpp/src/sfntly/data/byte_array.cc | 12 | ||||
-rw-r--r-- | cpp/src/sfntly/data/font_input_stream.cc | 4 | ||||
-rw-r--r-- | cpp/src/sfntly/data/font_output_stream.cc | 2 | ||||
-rw-r--r-- | cpp/src/sfntly/data/memory_byte_array.cc | 2 | ||||
-rw-r--r-- | cpp/src/sfntly/data/readable_font_data.cc | 8 | ||||
-rw-r--r-- | cpp/src/sfntly/font.cc | 16 | ||||
-rw-r--r-- | cpp/src/sfntly/glyph_table.cc | 8 | ||||
-rw-r--r-- | cpp/src/sfntly/horizontal_metrics_table.cc | 12 | ||||
-rw-r--r-- | cpp/src/sfntly/loca_table.cc | 24 | ||||
-rw-r--r-- | cpp/src/sfntly/name_table.cc | 2 | ||||
-rw-r--r-- | cpp/src/sfntly/port/exception_type.h | 4 | ||||
-rw-r--r-- | cpp/src/sfntly/port/file_input_stream.cc | 26 | ||||
-rw-r--r-- | cpp/src/sfntly/port/type.h | 2 | ||||
-rw-r--r-- | cpp/src/sfntly/table.cc | 12 | ||||
-rw-r--r-- | cpp/src/sfntly/tools/subsetter/glyph_table_subsetter.cc | 8 | ||||
-rw-r--r-- | cpp/src/test/byte_array_test.cc | 8 | ||||
-rw-r--r-- | cpp/src/test/font_data_test.cc | 4 | ||||
-rw-r--r-- | cpp/src/test/smart_pointer_test.cc | 42 |
20 files changed, 152 insertions, 48 deletions
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 3712432..409ae32 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 2.6.2) set(CMAKE_LEGACY_CYGWIN_WIN32 0) project(sfntly) +# Uncomment the line below to simulate Chrome compilation flags +# add_definitions(-DSFNTLY_NO_EXCEPTION -Wall -Werror -fno-exceptions) set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ext/gtest/include ext/gtest) diff --git a/cpp/src/sfntly/cmap_table.cc b/cpp/src/sfntly/cmap_table.cc index 11b2b50..79b083a 100644 --- a/cpp/src/sfntly/cmap_table.cc +++ b/cpp/src/sfntly/cmap_table.cc @@ -445,7 +445,7 @@ CALLER_ATTACH FontDataTable* CMapTable::CMapFormat2::Builder::subBuildTable( * CMapTable::Iterator class ******************************************************************************/ CMapTable::CMapIterator::CMapIterator(CMapTable* table, CMapFilter* filter) - : table_index_(0), table_(table), filter_(filter) {} + : table_index_(0), filter_(filter), table_(table) {} bool CMapTable::CMapIterator::hasNext() { if (!filter_) { diff --git a/cpp/src/sfntly/data/byte_array.cc b/cpp/src/sfntly/data/byte_array.cc index 3511bfe..d5af22e 100644 --- a/cpp/src/sfntly/data/byte_array.cc +++ b/cpp/src/sfntly/data/byte_array.cc @@ -121,7 +121,11 @@ int32_t ByteArray::copyTo(int32_t dst_offset, ByteArray* array, while ((bytes_read = get(index + src_offset, &b, 0, buffer_length)) > 0) { int bytes_written = array->put(index + dst_offset, &b, 0, bytes_read); if (bytes_written != bytes_read) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("Error writing bytes."); +#endif } index += bytes_read; remaining_length -= bytes_read; @@ -155,7 +159,11 @@ bool ByteArray::copyFrom(InputStream* is, int32_t length) { while ((bytes_read = is->read(&b, 0, buffer_length)) > 0) { if (put(index, &b, 0, bytes_read) != bytes_read) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("Error writing bytes."); +#endif } index += bytes_read; length -= bytes_read; @@ -172,7 +180,11 @@ bool ByteArray::copyFrom(InputStream* is) { while ((bytes_read = is->read(&b, 0, buffer_length)) > 0) { if (put(index, &b, 0, bytes_read) != bytes_read) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("Error writing bytes."); +#endif } index += bytes_read; } diff --git a/cpp/src/sfntly/data/font_input_stream.cc b/cpp/src/sfntly/data/font_input_stream.cc index 8b1d798..97c5860 100644 --- a/cpp/src/sfntly/data/font_input_stream.cc +++ b/cpp/src/sfntly/data/font_input_stream.cc @@ -21,11 +21,11 @@ namespace sfntly { FontInputStream::FontInputStream(InputStream* is) - : position_(0), length_(0), bounded_(false), stream_(is) { + : stream_(is), position_(0), length_(0), bounded_(false) { } FontInputStream::FontInputStream(InputStream* is, size_t length) - : position_(0), length_(length), bounded_(false), stream_(is) { + : stream_(is), position_(0), length_(length), bounded_(false) { } FontInputStream::~FontInputStream() { diff --git a/cpp/src/sfntly/data/font_output_stream.cc b/cpp/src/sfntly/data/font_output_stream.cc index d5eaa82..86a153c 100644 --- a/cpp/src/sfntly/data/font_output_stream.cc +++ b/cpp/src/sfntly/data/font_output_stream.cc @@ -22,7 +22,7 @@ namespace sfntly { FontOutputStream::FontOutputStream(OutputStream* os) - : position_(0), stream_(os) { + : stream_(os), position_(0) { } FontOutputStream::~FontOutputStream() { diff --git a/cpp/src/sfntly/data/memory_byte_array.cc b/cpp/src/sfntly/data/memory_byte_array.cc index 1e85ebd..528979a 100644 --- a/cpp/src/sfntly/data/memory_byte_array.cc +++ b/cpp/src/sfntly/data/memory_byte_array.cc @@ -22,7 +22,7 @@ namespace sfntly { // Note: this constructor can fail under low-memory situation MemoryByteArray::MemoryByteArray(int32_t length) - : ByteArray(0, length), allocated_(true), b_(NULL) { + : ByteArray(0, length), b_(NULL), allocated_(true) { } MemoryByteArray::MemoryByteArray(byte_t* b, int32_t buffer_length) diff --git a/cpp/src/sfntly/data/readable_font_data.cc b/cpp/src/sfntly/data/readable_font_data.cc index 3073b03..fa7279e 100644 --- a/cpp/src/sfntly/data/readable_font_data.cc +++ b/cpp/src/sfntly/data/readable_font_data.cc @@ -23,16 +23,16 @@ namespace sfntly { ReadableFontData::~ReadableFontData() {} ReadableFontData::ReadableFontData(ByteArray* array) - : FontData(array), checksum_(0), checksum_set_(false) { + : FontData(array), checksum_set_(false), checksum_(0) { } ReadableFontData::ReadableFontData(ReadableFontData* data, int32_t offset) - : FontData(data, offset), checksum_(0), checksum_set_(false) { + : FontData(data, offset), checksum_set_(false), checksum_(0) { } ReadableFontData::ReadableFontData(ReadableFontData* data, int32_t offset, int32_t length) - : FontData(data, offset, length), checksum_(0), checksum_set_(false) { + : FontData(data, offset, length), checksum_set_(false), checksum_(0) { } int64_t ReadableFontData::checksum() { @@ -133,9 +133,11 @@ int64_t ReadableFontData::readULong(int32_t index) { int32_t ReadableFontData::readULongAsInt(int32_t index) { int64_t ulong = readULong(index); +#if !defined (SFNTLY_NO_EXCEPTION) if ((ulong & 0x80000000) == 0x80000000) { throw ArithmeticException("Long value too large to fit into an integer."); } +#endif return ((int32_t)ulong) & ~0x80000000; } diff --git a/cpp/src/sfntly/font.cc b/cpp/src/sfntly/font.cc index 1ef222a..46dc48c 100644 --- a/cpp/src/sfntly/font.cc +++ b/cpp/src/sfntly/font.cc @@ -118,8 +118,8 @@ const int32_t Font::Offset::kTableRecordSize = 16; Font::~Font() {} Font::Font(FontFactory* factory, int32_t sfnt_version, ByteVector* digest, - TableMap* tables) : - sfnt_version_(sfnt_version), factory_(factory) { + TableMap* tables) + : factory_(factory), sfnt_version_(sfnt_version) { // non-trivial assignments that makes debugging hard if placed in // initialization list digest_ = *digest; @@ -223,7 +223,11 @@ void Font::serializeTables(FontOutputStream* fos, record != end_of_headers; ++record) { TablePtr target_table = table((*record)->tag()); if (target_table == NULL) { +#if defined (SFNTLY_NO_EXCEPTION) + return; +#else throw IOException("Table out of sync with font header."); +#endif } int32_t table_size = target_table->serialize(fos); int32_t filler_size = ((table_size + 3) & ~3) - table_size; @@ -462,19 +466,27 @@ void Font::Builder::buildTablesFromBuilders(TableBuilderMap* builder_map, builder != builder_end; ++builder) { TablePtr table; if (builder->second->readyToBuild()) { +#if !defined (SFNTLY_NO_EXCEPTION) try { +#endif table.attach(down_cast<Table*>(builder->second->build())); +#if !defined (SFNTLY_NO_EXCEPTION) } catch(IOException& e) { std::string builder_string = "Unable to build table - "; builder_string += typeid(builder->second).name(); builder_string += e.what(); throw RuntimeException(builder_string.c_str()); } +#endif } if (table == NULL) { +#if defined (SFNTLY_NO_EXCEPTION) + return; +#else std::string builder_string = "Unable to build table - "; builder_string += typeid(builder->second).name(); throw RuntimeException(builder_string.c_str()); +#endif } table_map->insert(TableMapEntry(table->header()->tag(), table)); } diff --git a/cpp/src/sfntly/glyph_table.cc b/cpp/src/sfntly/glyph_table.cc index 72f6945..4cd6436 100644 --- a/cpp/src/sfntly/glyph_table.cc +++ b/cpp/src/sfntly/glyph_table.cc @@ -109,8 +109,12 @@ void GlyphTable::Builder::initialize(ReadableFontData* data, const IntegerList& loca) { if (data != NULL) { if (loca_.empty()) { +#if defined (SFNTLY_NO_EXCEPTION) + return; +#else throw IllegalStateException( "Loca values not set - unable to parse glyph data."); +#endif } int32_t loca_value; int32_t last_loca_value = loca[0]; @@ -513,8 +517,8 @@ CALLER_ATTACH FontDataTable* * GlyphTable::CompositeGlyph and its builder ******************************************************************************/ GlyphTable::CompositeGlyph::CompositeGlyph(ReadableFontData* data) - : instruction_size_(0), instructions_offset_(0), - GlyphTable::Glyph(data, GlyphType::kComposite) { + : GlyphTable::Glyph(data, GlyphType::kComposite), + instruction_size_(0), instructions_offset_(0) { parseData(); } diff --git a/cpp/src/sfntly/horizontal_metrics_table.cc b/cpp/src/sfntly/horizontal_metrics_table.cc index 4ed2d43..d6beab1 100644 --- a/cpp/src/sfntly/horizontal_metrics_table.cc +++ b/cpp/src/sfntly/horizontal_metrics_table.cc @@ -54,7 +54,11 @@ int32_t HorizontalMetricsTable::numberOfLSBs() { int32_t HorizontalMetricsTable::hMetricAdvanceWidth(int32_t entry) { if (entry > num_hmetrics_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException(); +#endif } int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + Offset::kHMetricsAdvanceWidth; @@ -63,7 +67,11 @@ int32_t HorizontalMetricsTable::hMetricAdvanceWidth(int32_t entry) { int32_t HorizontalMetricsTable::hMetricLSB(int32_t entry) { if (entry > num_hmetrics_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException(); +#endif } int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + Offset::kHMetricsLeftSideBearing; @@ -72,7 +80,11 @@ int32_t HorizontalMetricsTable::hMetricLSB(int32_t entry) { int32_t HorizontalMetricsTable::lsbTableEntry(int32_t entry) { if (entry > num_hmetrics_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException(); +#endif } int32_t offset = Offset::kHMetricsStart + (entry * Offset::kHMetricsSize) + Offset::kLeftSideBearingSize; diff --git a/cpp/src/sfntly/loca_table.cc b/cpp/src/sfntly/loca_table.cc index 5bb5dd4..1cd1d92 100644 --- a/cpp/src/sfntly/loca_table.cc +++ b/cpp/src/sfntly/loca_table.cc @@ -36,14 +36,22 @@ int32_t LocaTable::numGlyphs() { int32_t LocaTable::glyphOffset(int32_t glyph_id) { if (glyph_id < 0 || glyph_id >= num_glyphs_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif } return loca(glyph_id); } int32_t LocaTable::glyphLength(int32_t glyph_id) { if (glyph_id < 0 || glyph_id >= num_glyphs_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif } return loca(glyph_id + 1) - loca(glyph_id); } @@ -54,7 +62,11 @@ int32_t LocaTable::numLocas() { int32_t LocaTable::loca(int32_t index) { if (index > num_glyphs_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException(); +#endif } if (version_ == IndexToLocFormat::kShortOffset) { return 2 * data_->readShort(index * DataSize::kUSHORT); @@ -102,7 +114,11 @@ LocaTable::Builder::~Builder() {} void LocaTable::Builder::initialize(ReadableFontData* data) { if (data) { if (numGlyphs() < 0) { +#if defined (SFNTLY_NO_EXCEPTION) + return; +#else throw IllegalStateException("numglyphs not set on LocaTable Builder."); +#endif } LocaTablePtr table = new LocaTable(header(), data, format_version_, num_glyphs_); @@ -140,14 +156,22 @@ void LocaTable::Builder::setLocaList(IntegerList* list) { int32_t LocaTable::Builder::glyphOffset(int32_t glyph_id) { if (glyph_id < 0 || glyph_id > (num_glyphs_ + 1)) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif } return loca(glyph_id); } int32_t LocaTable::Builder::glyphLength(int32_t glyph_id) { if (glyph_id < 0 || glyph_id > (num_glyphs_ + 1)) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IndexOutOfBoundException("Glyph ID is out of bounds."); +#endif } return loca(glyph_id + 1) - loca(glyph_id); } diff --git a/cpp/src/sfntly/name_table.cc b/cpp/src/sfntly/name_table.cc index e303d6d..b344bfa 100644 --- a/cpp/src/sfntly/name_table.cc +++ b/cpp/src/sfntly/name_table.cc @@ -549,7 +549,7 @@ NameTable::NameEntryBuilder::~NameEntryBuilder() {} ******************************************************************************/ NameTable::NameEntryIterator::NameEntryIterator(NameTable* table, NameEntryFilter* filter) : - table_(table), filter_(filter), name_index_(0) { + table_(table), name_index_(0), filter_(filter) { } bool NameTable::NameEntryIterator::hasNext() { diff --git a/cpp/src/sfntly/port/exception_type.h b/cpp/src/sfntly/port/exception_type.h index 56a93ff..2ba199a 100644 --- a/cpp/src/sfntly/port/exception_type.h +++ b/cpp/src/sfntly/port/exception_type.h @@ -19,6 +19,8 @@ #ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ #define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ +#if !defined (SFNTLY_NO_EXCEPTION) + #include <exception> #include <string> @@ -104,4 +106,6 @@ class IllegalStateException : public Exception { } // namespace sfntly +#endif // #if !defined (SFNTLY_NO_EXCEPTION) + #endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_EXCEPTION_TYPE_H_ diff --git a/cpp/src/sfntly/port/file_input_stream.cc b/cpp/src/sfntly/port/file_input_stream.cc index 7505ab7..dcb37f7 100644 --- a/cpp/src/sfntly/port/file_input_stream.cc +++ b/cpp/src/sfntly/port/file_input_stream.cc @@ -23,7 +23,7 @@ namespace sfntly { -FileInputStream::FileInputStream() : file_(NULL), length_(0), position_(0) { +FileInputStream::FileInputStream() : file_(NULL), position_(0), length_(0) { } FileInputStream::~FileInputStream() { @@ -73,10 +73,18 @@ bool FileInputStream::markSupported() { int32_t FileInputStream::read() { if (!file_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("no opened file"); +#endif } if (feof(file_)) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("eof reached"); +#endif } byte_t value; fread(&value, 1, 1, file_); @@ -92,10 +100,18 @@ int32_t FileInputStream::read(ByteVector* b, int32_t offset, int32_t length) { assert(b); assert(b->size() >= (size_t)(offset + length)); if (!file_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("no opened file"); +#endif } if (feof(file_)) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("eof reached"); +#endif } size_t read_count = std::min<size_t>(length_ - position_, length); int32_t actual_read = fread(&((*b)[offset]), 1, read_count, file_); @@ -109,7 +125,11 @@ void FileInputStream::reset() { int64_t FileInputStream::skip(int64_t n) { if (!file_) { +#if defined (SFNTLY_NO_EXCEPTION) + return 0; +#else throw IOException("no opened file"); +#endif } if (n < 0) { return 0; @@ -128,7 +148,11 @@ void FileInputStream::unread(ByteVector* b, int32_t offset, int32_t length) { assert(b); assert(b->size() >= size_t(offset + length)); if (!file_) { +#if defined (SFNTLY_NO_EXCEPTION) + return; +#else throw IOException("no opened file"); +#endif } size_t unread_count = std::min<size_t>(position_, length); fseek(file_, position_ - unread_count, SEEK_SET); diff --git a/cpp/src/sfntly/port/type.h b/cpp/src/sfntly/port/type.h index ab55b97..25b697e 100644 --- a/cpp/src/sfntly/port/type.h +++ b/cpp/src/sfntly/port/type.h @@ -78,7 +78,7 @@ inline To down_cast(From* f) { // so we only accept pointers } #if !defined(WIN32) - #define UNREFERENCED_PARAMETER(p) + #define UNREFERENCED_PARAMETER(p) do { (void)p; } while (0) #endif #endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_TYPE_H_ diff --git a/cpp/src/sfntly/table.cc b/cpp/src/sfntly/table.cc index 1215f50..856f32e 100644 --- a/cpp/src/sfntly/table.cc +++ b/cpp/src/sfntly/table.cc @@ -74,19 +74,19 @@ void Table::setFont(Font* font) { * Table::Header class ******************************************************************************/ Table::Header::Header(int32_t tag) - : tag_(tag), checksum_(0), checksum_valid_(false), offset_(0), length_(0), - offset_valid_(false) { + : tag_(tag), offset_(0), length_(0), offset_valid_(false), checksum_(0), + checksum_valid_(false) { } Table::Header::Header(int32_t tag, int32_t length) - : tag_(tag), checksum_(0), checksum_valid_(false), offset_(0), - length_(length), offset_valid_(false) { + : tag_(tag), offset_(0), length_(length), offset_valid_(false), + checksum_(0), checksum_valid_(false) { } Table::Header::Header(int32_t tag, int64_t checksum, int32_t offset, int32_t length) - : tag_(tag), checksum_(checksum), checksum_valid_(true), offset_(offset), - length_(length), offset_valid_(true) { + : tag_(tag), offset_(offset), length_(length), offset_valid_(true), + checksum_(checksum), checksum_valid_(true) { } Table::Header::~Header() {} diff --git a/cpp/src/sfntly/tools/subsetter/glyph_table_subsetter.cc b/cpp/src/sfntly/tools/subsetter/glyph_table_subsetter.cc index 93a8852..04d0c48 100644 --- a/cpp/src/sfntly/tools/subsetter/glyph_table_subsetter.cc +++ b/cpp/src/sfntly/tools/subsetter/glyph_table_subsetter.cc @@ -44,7 +44,11 @@ bool GlyphTableSubsetter::subset(Subsetter* subsetter, Font* font, GlyphTablePtr glyph_table = down_cast<GlyphTable*>(font->table(Tag::glyf)); LocaTablePtr loca_table = down_cast<LocaTable*>(font->table(Tag::loca)); if (glyph_table == NULL || loca_table == NULL) { +#if defined (SFNTLY_NO_EXCEPTION) + return false; +#else throw RuntimeException("Font to subset is not valid."); +#endif } GlyphTableBuilderPtr glyph_table_builder; @@ -54,7 +58,11 @@ bool GlyphTableSubsetter::subset(Subsetter* subsetter, Font* font, loca_table_builder.attach(down_cast<LocaTable::Builder*>( font_builder->newTableBuilder(Tag::loca))); if (glyph_table_builder == NULL || loca_table_builder == NULL) { +#if defined (SFNTLY_NO_EXCEPTION) + return false; +#else throw RuntimeException("Builder for subset is not valid."); +#endif } GlyphTable::GlyphBuilderList* glyph_builders = glyph_table_builder->glyphBuilders(); diff --git a/cpp/src/test/byte_array_test.cc b/cpp/src/test/byte_array_test.cc index d2c865f..7c6efa9 100644 --- a/cpp/src/test/byte_array_test.cc +++ b/cpp/src/test/byte_array_test.cc @@ -112,10 +112,10 @@ bool byteArrayTester(ByteArray* ba) { } // namespace byte_array_test bool testMemoryByteArray() { - for (int32_t i = 0; + for (size_t i = 0; i < sizeof(byte_array_test::BYTE_ARRAY_SIZES) / sizeof(int32_t); ++i) { int32_t size = byte_array_test::BYTE_ARRAY_SIZES[i]; - fprintf(stderr, "fixed mem: iteration %d, size %d\n", i, size); + fprintf(stderr, "fixed mem: iteration %ld, size %d\n", i, size); ByteArrayPtr ba = new MemoryByteArray(size); byte_array_test::fillTestByteArray(ba, size); EXPECT_TRUE(byte_array_test::byteArrayTester(ba)); @@ -124,10 +124,10 @@ bool testMemoryByteArray() { } bool testGrowableMemoryByteArray() { - for (int32_t i = 0; + for (size_t i = 0; i < sizeof(byte_array_test::BYTE_ARRAY_SIZES) / sizeof(int32_t); ++i) { int32_t size = byte_array_test::BYTE_ARRAY_SIZES[i]; - fprintf(stderr, "growable mem: iteration %d, size %d\n", i, size); + fprintf(stderr, "growable mem: iteration %ld, size %d\n", i, size); ByteArrayPtr ba = new GrowableMemoryByteArray(); byte_array_test::fillTestByteArray(ba, size); EXPECT_TRUE(byte_array_test::byteArrayTester(ba)); diff --git a/cpp/src/test/font_data_test.cc b/cpp/src/test/font_data_test.cc index 1e81626..ad30522 100644 --- a/cpp/src/test/font_data_test.cc +++ b/cpp/src/test/font_data_test.cc @@ -186,7 +186,7 @@ void slicingWriteTest(ReadableFontData* rfd, WritableFontData* wfd) { } bool testReadableFontData() { - for (int32_t i = 0; i < sizeof(BYTE_ARRAY_SIZES) / sizeof(int32_t); ++i) { + for (size_t i = 0; i < sizeof(BYTE_ARRAY_SIZES) / sizeof(int32_t); ++i) { int32_t size = BYTE_ARRAY_SIZES[i]; ByteArrayPtr ba = new MemoryByteArray(size); fillTestByteArray(ba, size); @@ -197,7 +197,7 @@ bool testReadableFontData() { } bool testWritableFontData() { - for (int32_t i = 0; i < sizeof(BYTE_ARRAY_SIZES) / sizeof(int32_t); ++i) { + for (size_t i = 0; i < sizeof(BYTE_ARRAY_SIZES) / sizeof(int32_t); ++i) { int32_t size = BYTE_ARRAY_SIZES[i]; ByteArrayPtr ba = new MemoryByteArray(size); fillTestByteArray(ba, size); diff --git a/cpp/src/test/smart_pointer_test.cc b/cpp/src/test/smart_pointer_test.cc index 8bc9f99..a35e289 100644 --- a/cpp/src/test/smart_pointer_test.cc +++ b/cpp/src/test/smart_pointer_test.cc @@ -33,44 +33,44 @@ bool testSmartPointer() { { Ptr<Foo> p1; p1 = new Foo(); - EXPECT_EQ(1, p1->ref_count_); - EXPECT_EQ(1, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(1), p1->ref_count_); + EXPECT_EQ(size_t(1), RefCounted<Foo>::object_counter_); Ptr<Foo> p2; p2 = p1; - EXPECT_EQ(2, p1->ref_count_); - EXPECT_EQ(2, p2->ref_count_); - EXPECT_EQ(1, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(2), p1->ref_count_); + EXPECT_EQ(size_t(2), p2->ref_count_); + EXPECT_EQ(size_t(1), RefCounted<Foo>::object_counter_); Ptr<Foo> p3; p3 = p1; - EXPECT_EQ(3, p1->ref_count_); - EXPECT_EQ(3, p2->ref_count_); - EXPECT_EQ(3, p3->ref_count_); - EXPECT_EQ(1, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(3), p1->ref_count_); + EXPECT_EQ(size_t(3), p2->ref_count_); + EXPECT_EQ(size_t(3), p3->ref_count_); + EXPECT_EQ(size_t(1), RefCounted<Foo>::object_counter_); p2 = new Foo(); - EXPECT_EQ(2, p1->ref_count_); - EXPECT_EQ(1, p2->ref_count_); - EXPECT_EQ(2, p3->ref_count_); - EXPECT_EQ(2, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(2), p1->ref_count_); + EXPECT_EQ(size_t(1), p2->ref_count_); + EXPECT_EQ(size_t(2), p3->ref_count_); + EXPECT_EQ(size_t(2), RefCounted<Foo>::object_counter_); p3.release(); - EXPECT_EQ(1, p1->ref_count_); + EXPECT_EQ(size_t(1), p1->ref_count_); EXPECT_EQ(NULL, p3.p_); - EXPECT_EQ(2, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(2), RefCounted<Foo>::object_counter_); p2 = NULL; - EXPECT_EQ(1, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(1), RefCounted<Foo>::object_counter_); p1 = p1; - EXPECT_EQ(1, p1->ref_count_); - EXPECT_EQ(1, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(1), p1->ref_count_); + EXPECT_EQ(size_t(1), RefCounted<Foo>::object_counter_); p1 = &(*p1); - EXPECT_EQ(1, p1->ref_count_); - EXPECT_EQ(1, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(1), p1->ref_count_); + EXPECT_EQ(size_t(1), RefCounted<Foo>::object_counter_); } - EXPECT_EQ(0, RefCounted<Foo>::object_counter_); + EXPECT_EQ(size_t(0), RefCounted<Foo>::object_counter_); return true; } |