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 21:55:04 UTC

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

Author: hwright
Date: Thu Sep 16 19:55:03 2010
New Revision: 997897

URL: http://svn.apache.org/viewvc?rev=997897&view=rev
Log:
On the object-model branch:
Add a Revision class, modeled after the JavaHL version, and a new test.

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

* subversion/bindings/c++/include/Revision.h:
  New.

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

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

Added: subversion/branches/object-model/subversion/bindings/c++/Revision.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/Revision.cpp?rev=997897&view=auto
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/Revision.cpp (added)
+++ subversion/branches/object-model/subversion/bindings/c++/Revision.cpp Thu Sep 16 19:55:03 2010
@@ -0,0 +1,91 @@
+/**
+ * @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
+ *
+ */
+
+#include "Revision.h"
+
+namespace SVN {
+
+const Revision Revision::HEAD(svn_opt_revision_head);
+const Revision Revision::COMMITTED(svn_opt_revision_committed);
+const Revision Revision::PREVIOUS(svn_opt_revision_previous);
+const Revision Revision::BASE(svn_opt_revision_base);
+const Revision Revision::WORKING(svn_opt_revision_working);
+
+Revision::Revision(svn_opt_revision_kind kind)
+{
+  m_revision.kind = kind;
+}
+
+Revision::Revision(svn_revnum_t revnum)
+{
+  m_revision.kind = svn_opt_revision_number;
+  m_revision.value.number = revnum;
+}
+
+Revision::Revision(apr_time_t date, bool foo)
+{
+  m_revision.kind = svn_opt_revision_date;
+  m_revision.value.date = date;
+}
+
+Revision::~Revision()
+{
+}
+
+bool
+Revision::operator==(svn_opt_revision_t *rev) const
+{
+  if (rev->kind != m_revision.kind)
+      return false;
+
+  switch (rev->kind)
+    {
+      case svn_opt_revision_number:
+        return (rev->value.number == m_revision.value.number);
+      case svn_opt_revision_date:
+        return (rev->value.date == m_revision.value.date);
+      default:
+        return true;
+    }
+}
+
+const Revision
+Revision::getNumberRev(svn_revnum_t revnum)
+{
+  return Revision(revnum);
+}
+
+const Revision
+Revision::getDateRev(apr_time_t date)
+{
+  return Revision(date, false);
+}
+
+const svn_opt_revision_t *
+Revision::revision() const
+{
+  return &m_revision;
+}
+
+}

Added: subversion/branches/object-model/subversion/bindings/c++/include/Revision.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Revision.h?rev=997897&view=auto
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Revision.h (added)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Revision.h Thu Sep 16 19:55:03 2010
@@ -0,0 +1,67 @@
+/**
+ * @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 Revision.h
+ * @brief Interface of the class Revision
+ */
+
+#ifndef REVISION_H
+#define REVISION_H
+
+#include "svn_opt.h"
+
+#include <string>
+
+namespace SVN
+{
+
+  class Revision
+  {
+    private:
+      /** The constructors. */
+      Revision(svn_opt_revision_kind kind);
+      Revision(svn_revnum_t revnum);
+      Revision(apr_time_t date, bool foo);
+
+      svn_opt_revision_t m_revision;
+
+    public:
+      /** The destructor needs to be public. */
+      virtual ~Revision();
+
+      static const Revision getNumberRev(svn_revnum_t revnum);
+      static const Revision getDateRev(apr_time_t date);
+
+      const svn_opt_revision_t *revision() const;
+
+      bool operator==(svn_opt_revision_t *rev) const;
+
+      /** Some constant revision types. */
+      const static Revision HEAD;
+      const static Revision COMMITTED;
+      const static Revision PREVIOUS;
+      const static Revision BASE;
+      const static Revision WORKING;
+  };
+}
+
+#endif // REVISION_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=997897&r1=997896&r2=997897&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 19:55:03 2010
@@ -24,6 +24,7 @@
 #include "../svn_test.h"
 
 #include "Pool.h"
+#include "Revision.h"
 
 using namespace SVN;
 
@@ -38,6 +39,33 @@ test_pools(apr_pool_t *p)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_revision(apr_pool_t *p)
+{
+  SVN_TEST_ASSERT(Revision::HEAD.revision()->kind == svn_opt_revision_head);
+  SVN_TEST_ASSERT(Revision::COMMITTED.revision()->kind
+                                             == svn_opt_revision_committed);
+  SVN_TEST_ASSERT(Revision::PREVIOUS.revision()->kind
+                                             == svn_opt_revision_previous);
+  SVN_TEST_ASSERT(Revision::BASE.revision()->kind == svn_opt_revision_base);
+  SVN_TEST_ASSERT(Revision::WORKING.revision()->kind
+                                             == svn_opt_revision_working);
+
+  Revision r1 = Revision::getNumberRev(1);
+  svn_opt_revision_t rev;
+  rev.kind = svn_opt_revision_number;
+  rev.value.number = 1;
+  SVN_TEST_ASSERT(r1 == &rev);
+
+  apr_time_t date = 0xdeadbeef;
+  Revision rToday = Revision::getDateRev(date);
+  rev.kind = svn_opt_revision_date;
+  rev.value.date = date;
+  SVN_TEST_ASSERT(rToday == &rev);
+
+  return SVN_NO_ERROR;
+}
+
 /* The test table.  */
 
 struct svn_test_descriptor_t test_funcs[] =
@@ -45,5 +73,7 @@ struct svn_test_descriptor_t test_funcs[
     SVN_TEST_NULL,
     SVN_TEST_PASS2(test_pools,
                    "test Pool class"),
+    SVN_TEST_PASS2(test_revision,
+                   "test Revision class"),
     SVN_TEST_NULL
   };