[PATCH] D28515: [Support] - Introduce zlib::toString(zlib::Status)
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 11 02:02:58 PST 2017
grimar updated this revision to Diff 83931.
grimar added a comment.
- Added unittest
- Made toString() to be single implementation for cases when ZLib is available/NA
https://reviews.llvm.org/D28515
Files:
include/llvm/Support/Compression.h
lib/Support/Compression.cpp
unittests/Support/CompressionTest.cpp
Index: unittests/Support/CompressionTest.cpp
===================================================================
--- unittests/Support/CompressionTest.cpp
+++ unittests/Support/CompressionTest.cpp
@@ -67,4 +67,15 @@
#endif
+TEST(CompressionTest, ZlibMessages) {
+ EXPECT_EQ("", zlib::toString(zlib::StatusOK));
+ EXPECT_EQ("zlib is unavailable", zlib::toString(zlib::StatusUnsupported));
+ EXPECT_EQ("there was not enough memory",
+ zlib::toString(zlib::StatusOutOfMemory));
+ EXPECT_EQ("there was not enough room in the output buffer",
+ zlib::toString(zlib::StatusBufferTooShort));
+ EXPECT_EQ("invalid input parameter", zlib::toString(zlib::StatusInvalidArg));
+ EXPECT_EQ("data was corrupted or incomplete",
+ zlib::toString(zlib::StatusInvalidData));
+}
}
Index: lib/Support/Compression.cpp
===================================================================
--- lib/Support/Compression.cpp
+++ lib/Support/Compression.cpp
@@ -108,3 +108,21 @@
}
#endif
+StringRef zlib::toString(zlib::Status Stat) {
+ switch (Stat) {
+ case zlib::StatusOK:
+ return "";
+ case zlib::StatusUnsupported:
+ return "zlib is unavailable";
+ case zlib::StatusOutOfMemory:
+ return "there was not enough memory";
+ case zlib::StatusBufferTooShort:
+ return "there was not enough room in the output buffer";
+ case zlib::StatusInvalidArg:
+ return "invalid input parameter";
+ case zlib::StatusInvalidData:
+ return "data was corrupted or incomplete";
+ default:
+ llvm_unreachable("status unknown");
+ }
+}
Index: include/llvm/Support/Compression.h
===================================================================
--- include/llvm/Support/Compression.h
+++ include/llvm/Support/Compression.h
@@ -52,6 +52,8 @@
uint32_t crc32(StringRef Buffer);
+StringRef toString(Status Stat);
+
} // End of namespace zlib
} // End of namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28515.83931.patch
Type: text/x-patch
Size: 1952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170111/809f1c48/attachment.bin>
More information about the llvm-commits
mailing list