diff options
author | Yi Jin <jinyithu@google.com> | 2018-04-05 12:41:36 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-04-05 12:41:36 -0700 |
commit | d01a55dcf17efefb930969d33cf43c6f977187d6 (patch) | |
tree | 05fe80b52412ff10054dda113a2fa82dd63b7801 /libs | |
parent | dd02f9fb0c5d0d01fbf5a4c2a6330bbebf5e605e (diff) | |
parent | dceecbd1fa0a2706f41b20061dbec638ab5b995b (diff) | |
download | base-d01a55dcf17efefb930969d33cf43c6f977187d6.tar.gz |
Merge "This cl tries to fix cts tests IncidentdTest" into pi-dev am: 72a39eb3be
am: dceecbd1fa
Change-Id: If7909669f4a898583b5c65d1b72a9d6f890e9284
Diffstat (limited to 'libs')
-rw-r--r-- | libs/protoutil/Android.bp | 17 | ||||
-rw-r--r-- | libs/protoutil/AndroidTest.xml | 26 | ||||
-rw-r--r-- | libs/protoutil/src/EncodedBuffer.cpp | 10 | ||||
-rw-r--r-- | libs/protoutil/tests/EncodedBuffer_test.cpp | 25 |
4 files changed, 74 insertions, 4 deletions
diff --git a/libs/protoutil/Android.bp b/libs/protoutil/Android.bp index 4f1d2d5a4fe5..7ad83ca79695 100644 --- a/libs/protoutil/Android.bp +++ b/libs/protoutil/Android.bp @@ -37,3 +37,20 @@ cc_library { "liblog", ], } + +cc_test { + name: "libprotoutil_test", + + srcs: [ + "tests/EncodedBuffer_test.cpp", + ], + + shared_libs: [ + "libcutils", + "libprotoutil", + ], + + static_libs: [ + "libgmock", + ], +} diff --git a/libs/protoutil/AndroidTest.xml b/libs/protoutil/AndroidTest.xml new file mode 100644 index 000000000000..46d418e1bb0a --- /dev/null +++ b/libs/protoutil/AndroidTest.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2018 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<configuration description="Config for libprotoutil_test"> + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <option name="cleanup" value="true" /> + <option name="push" value="libprotoutil_test->/data/nativetest/libprotoutil_test" /> + </target_preparer> + <option name="test-suite-tag" value="apct" /> + <test class="com.android.tradefed.testtype.GTest" > + <option name="native-test-device-path" value="/data/nativetest" /> + <option name="module-name" value="libprotoutil_test" /> + </test> +</configuration> diff --git a/libs/protoutil/src/EncodedBuffer.cpp b/libs/protoutil/src/EncodedBuffer.cpp index 3a5e2e9ef5d0..c017851a1623 100644 --- a/libs/protoutil/src/EncodedBuffer.cpp +++ b/libs/protoutil/src/EncodedBuffer.cpp @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define LOG_TAG "libprotoutil" + +#include <stdlib.h> #include <android/util/EncodedBuffer.h> #include <android/util/protobuf.h> - -#include <stdlib.h> +#include <cutils/log.h> namespace android { namespace util { @@ -228,7 +230,7 @@ EncodedBuffer::readRawVarint() size_t start = mEp.pos(); while (true) { uint8_t byte = readRawByte(); - val += (byte & 0x7F) << shift; + val |= (UINT64_C(0x7F) & byte) << shift; if ((byte & 0x80) == 0) break; shift += 7; } @@ -345,7 +347,7 @@ EncodedBuffer::iterator::readRawVarint() uint64_t val = 0, shift = 0; while (true) { uint8_t byte = next(); - val += (byte & 0x7F) << shift; + val |= (INT64_C(0x7F) & byte) << shift; if ((byte & 0x80) == 0) break; shift += 7; } diff --git a/libs/protoutil/tests/EncodedBuffer_test.cpp b/libs/protoutil/tests/EncodedBuffer_test.cpp new file mode 100644 index 000000000000..615ab4ab29ed --- /dev/null +++ b/libs/protoutil/tests/EncodedBuffer_test.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include <android/util/EncodedBuffer.h> +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +using namespace android::util; + +TEST(EncodedBufferTest, ReadVarint) { + EncodedBuffer buffer; + uint64_t val = UINT64_C(1522865904593); + buffer.writeRawVarint64(val); + EXPECT_EQ(val, buffer.begin().readRawVarint()); +} |