Move TestPythonFileObjectAdapter into a new test_util file.
This will be used to test the NewCcEncryptingStream wrapper function.
PiperOrigin-RevId: 268636936
diff --git a/python/cc/BUILD.bazel b/python/cc/BUILD.bazel
index 183e934..6e47697 100644
--- a/python/cc/BUILD.bazel
+++ b/python/cc/BUILD.bazel
@@ -52,8 +52,8 @@
srcs = ["python_output_stream_test.cc"],
linkopts = ["-lpthread"],
deps = [
- ":python_file_object_adapter",
":python_output_stream",
+ ":test_util",
"//cc/subtle:random",
"//cc/util:status",
"//cc/util:statusor",
@@ -91,3 +91,13 @@
"@com_google_googletest//:gtest_main",
],
)
+
+cc_library(
+ name = "test_util",
+ hdrs = ["test_util.h"],
+ include_prefix = "tink/python",
+ strip_include_prefix = "/python",
+ deps = [
+ ":python_file_object_adapter",
+ ],
+)
diff --git a/python/cc/python_output_stream_test.cc b/python/cc/python_output_stream_test.cc
index 6ac4a3e..a8ec476 100644
--- a/python/cc/python_output_stream_test.cc
+++ b/python/cc/python_output_stream_test.cc
@@ -23,28 +23,12 @@
#include "tink/subtle/random.h"
#include "tink/util/status.h"
#include "tink/util/statusor.h"
-#include "tink/python/cc/python_file_object_adapter.h"
+#include "tink/python/cc/test_util.h"
namespace crypto {
namespace tink {
namespace {
-// PythonFileObjectAdapter for testing.
-class TestPythonFileObjectAdapter : public PythonFileObjectAdapter {
- public:
- util::StatusOr<int> Write(absl::string_view data) override {
- buffer_ += std::string(data);
- return data.size();
- }
-
- util::Status Close() override { return util::OkStatus(); }
-
- std::string* GetBuffer() { return &buffer_; }
-
- private:
- std::string buffer_;
-};
-
// Writes 'contents' to the specified 'output_stream', and closes the stream.
// Returns the status of output_stream->Close()-operation, or a non-OK status
// of a prior output_stream->Next()-operation, if any.
@@ -74,7 +58,7 @@
for (size_t stream_size : {0, 10, 100, 1000, 10000, 100000, 1000000}) {
SCOPED_TRACE(absl::StrCat("stream_size = ", stream_size));
std::string stream_contents = subtle::Random::GetRandomBytes(stream_size);
- auto output = absl::make_unique<TestPythonFileObjectAdapter>();
+ auto output = absl::make_unique<test::TestPythonFileObjectAdapter>();
std::string* output_buffer = output->GetBuffer();
auto output_stream =
absl::make_unique<PythonOutputStream>(std::move(output));
@@ -90,7 +74,7 @@
std::string stream_contents = subtle::Random::GetRandomBytes(stream_size);
for (int buffer_size : {1, 10, 100, 1000, 10000, 100000, 1000000}) {
SCOPED_TRACE(absl::StrCat("buffer_size = ", buffer_size));
- auto output = absl::make_unique<TestPythonFileObjectAdapter>();
+ auto output = absl::make_unique<test::TestPythonFileObjectAdapter>();
std::string* output_buffer = output->GetBuffer();
auto output_stream =
absl::make_unique<PythonOutputStream>(std::move(output), buffer_size);
@@ -111,7 +95,7 @@
int buffer_size = 1234;
void* buffer;
std::string stream_contents = subtle::Random::GetRandomBytes(stream_size);
- auto output = absl::make_unique<TestPythonFileObjectAdapter>();
+ auto output = absl::make_unique<test::TestPythonFileObjectAdapter>();
std::string* output_buffer = output->GetBuffer();
// Prepare the stream and do the first call to Next().
diff --git a/python/cc/test_util.h b/python/cc/test_util.h
new file mode 100644
index 0000000..b8933c9
--- /dev/null
+++ b/python/cc/test_util.h
@@ -0,0 +1,46 @@
+// 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.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef TINK_PYTHON_CC_TEST_UTIL_H_
+#define TINK_PYTHON_CC_TEST_UTIL_H_
+
+#include "tink/python/cc/python_file_object_adapter.h"
+
+
+namespace crypto {
+namespace tink {
+namespace test {
+
+// PythonFileObjectAdapter for testing.
+class TestPythonFileObjectAdapter : public PythonFileObjectAdapter {
+ public:
+ util::StatusOr<int> Write(absl::string_view data) override {
+ buffer_ += std::string(data);
+ return data.size();
+ }
+
+ util::Status Close() override { return util::OkStatus(); }
+
+ std::string* GetBuffer() { return &buffer_; }
+
+ private:
+ std::string buffer_;
+};
+
+} // namespace test
+} // namespace tink
+} // namespace crypto
+
+
+#endif // TINK_PYTHON_CC_TEST_UTIL_H_