summaryrefslogtreecommitdiffstats
path: root/util/stream/aligned_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/stream/aligned_ut.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/stream/aligned_ut.cpp')
-rw-r--r--util/stream/aligned_ut.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/util/stream/aligned_ut.cpp b/util/stream/aligned_ut.cpp
new file mode 100644
index 00000000000..e980d05cf71
--- /dev/null
+++ b/util/stream/aligned_ut.cpp
@@ -0,0 +1,63 @@
+#include "aligned.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+class TNastyInputStream: public IInputStream {
+public:
+ TNastyInputStream()
+ : Pos_(0)
+ {
+ }
+
+protected:
+ size_t DoRead(void* buf, size_t len) override {
+ if (len == 0) {
+ return 0;
+ }
+
+ *static_cast<unsigned char*>(buf) = static_cast<unsigned char>(Pos_);
+ ++Pos_;
+ return 1;
+ }
+
+ size_t DoSkip(size_t len) override {
+ if (len == 0) {
+ return 0;
+ }
+
+ ++Pos_;
+ return 1;
+ }
+
+private:
+ size_t Pos_;
+};
+
+Y_UNIT_TEST_SUITE(TAlignedTest) {
+ Y_UNIT_TEST(AlignInput) {
+ TNastyInputStream input0;
+ TAlignedInput alignedInput(&input0);
+
+ char c = '\1';
+
+ alignedInput.Align(2);
+ alignedInput.ReadChar(c);
+ UNIT_ASSERT_VALUES_EQUAL(c, '\x0');
+
+ alignedInput.Align(2);
+ alignedInput.ReadChar(c);
+ UNIT_ASSERT_VALUES_EQUAL(c, '\x2');
+
+ alignedInput.Align(4);
+ alignedInput.ReadChar(c);
+ UNIT_ASSERT_VALUES_EQUAL(c, '\x4');
+
+ alignedInput.Align(16);
+ alignedInput.ReadChar(c);
+ UNIT_ASSERT_VALUES_EQUAL(c, '\x10');
+
+ alignedInput.Align(128);
+ alignedInput.ReadChar(c);
+ UNIT_ASSERT_VALUES_EQUAL(c, '\x80');
+ }
+}