You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2010/09/16 23:22:25 UTC

svn commit: r997928 - in /subversion/branches/object-model/subversion: bindings/c++/Utility.cpp bindings/c++/Utility.h tests/libsvn++/util-test.cpp

Author: hwright
Date: Thu Sep 16 21:22:24 2010
New Revision: 997928

URL: http://svn.apache.org/viewvc?rev=997928&view=rev
Log:
On the object-model branch:
Add a utility namespace, and put in it something to wrap a Subversion output
stream.  Also add a new test.

* subversion/bindings/c++/Utility.cpp:
  New.

* subversion/bindings/c++/Utility.h:
  New.

* subversion/tests/libsvn++/util-test.cpp
  (test_streams): New.
  (test_funcs): Run the new test.

Added:
    subversion/branches/object-model/subversion/bindings/c++/Utility.cpp
    subversion/branches/object-model/subversion/bindings/c++/Utility.h
Modified:
    subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp

Added: subversion/branches/object-model/subversion/bindings/c++/Utility.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/Utility.cpp?rev=997928&view=auto
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/Utility.cpp (added)
+++ subversion/branches/object-model/subversion/bindings/c++/Utility.cpp Thu Sep 16 21:22:24 2010
@@ -0,0 +1,62 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you 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.
+ * ====================================================================
+ * @endcopyright
+ *
+ * @file Utility.cpp
+ * @brief Implementation of the class Utility
+ */
+
+#include "Utility.h"
+#include "Pool.h"
+
+
+static svn_error_t *
+write_handler_ostream(void *baton, const char *data, apr_size_t *len)
+{
+  std::ostream *ostream = reinterpret_cast<std::ostream *>(baton);
+
+  ostream->write(data, *len);
+  return SVN_NO_ERROR;
+}
+
+namespace SVN
+{
+
+namespace Private
+{
+
+namespace Utility
+{
+
+svn_stream_t *
+ostream_wrapper(std::ostream &ostream, Pool &pool)
+{
+  svn_stream_t *stream;
+
+  stream = svn_stream_create(&ostream, pool.pool());
+  svn_stream_set_write(stream, write_handler_ostream);
+
+  return stream;
+}
+
+}
+}
+}

Added: subversion/branches/object-model/subversion/bindings/c++/Utility.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/Utility.h?rev=997928&view=auto
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/Utility.h (added)
+++ subversion/branches/object-model/subversion/bindings/c++/Utility.h Thu Sep 16 21:22:24 2010
@@ -0,0 +1,53 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you 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.
+ * ====================================================================
+ * @endcopyright
+ *
+ * @file Utility.h
+ * @brief Some utility functions
+ */
+
+#ifndef UTILITY_H
+#define UTILITY_H
+
+#include "Pool.h"
+
+#include "svn_pools.h"
+#include "svn_io.h"
+
+#include <ostream>
+
+namespace SVN
+{
+
+namespace Private
+{
+
+namespace Utility
+{
+
+svn_stream_t *
+ostream_wrapper(std::ostream &stream, Pool &pool);
+
+}
+}
+}
+
+#endif // UTILITY_H

Modified: subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/tests/libsvn%2B%2B/util-test.cpp?rev=997928&r1=997927&r2=997928&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp (original)
+++ subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp Thu Sep 16 21:22:24 2010
@@ -25,6 +25,9 @@
 
 #include "Pool.h"
 #include "Revision.h"
+#include "../Utility.h"
+
+#include <sstream>
 
 using namespace SVN;
 
@@ -68,6 +71,22 @@ test_revision(apr_pool_t *p)
   return SVN_NO_ERROR;
 }
 
+#define TEST_STR "Mary had a little lamb.\n"
+static svn_error_t *
+test_streams(apr_pool_t *p)
+{
+  Pool pool;
+  std::ostringstream oss;
+
+  svn_stream_t *out = Private::Utility::ostream_wrapper(oss, pool);
+  apr_size_t len = strlen(TEST_STR);
+
+  SVN_ERR(svn_stream_write(out, TEST_STR, &len));
+  SVN_TEST_ASSERT(oss.str() == TEST_STR);
+
+  return SVN_NO_ERROR;
+}
+
 /* The test table.  */
 
 struct svn_test_descriptor_t test_funcs[] =
@@ -77,5 +96,7 @@ struct svn_test_descriptor_t test_funcs[
                    "test Pool class"),
     SVN_TEST_PASS2(test_revision,
                    "test Revision class"),
+    SVN_TEST_PASS2(test_streams,
+                   "test stream wrapping"),
     SVN_TEST_NULL
   };