Matthias Brantner has proposed merging lp:~matthias-brantner/zorba/bug-fixing 
into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~matthias-brantner/zorba/bug-fixing/+merge/77630

Fix in the XQDDF documentation
-- 
https://code.launchpad.net/~matthias-brantner/zorba/bug-fixing/+merge/77630
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'doc/zorba/xqddf.dox'
--- doc/zorba/xqddf.dox	2011-09-14 06:15:19 +0000
+++ doc/zorba/xqddf.dox	2011-09-30 02:38:26 +0000
@@ -1266,6 +1266,7 @@
                      where $art/empid eq $emp/id
                      return $art)
   return $emp
+\endcode
 
 <a name="query_no_probe_3" id="query_no_probe_3"></a>
 \code

=== modified file 'include/zorba/audit.h'
--- include/zorba/audit.h	2011-08-19 23:22:48 +0000
+++ include/zorba/audit.h	2011-09-30 02:38:26 +0000
@@ -95,6 +95,8 @@
 
   class ZORBA_DLL_PUBLIC Event {
   public:
+    static Event* get();
+
     virtual bool audit(const Property&) const = 0;
     virtual bool audit(const String&) const = 0;
 

=== modified file 'include/zorba/audit_scoped.h'
--- include/zorba/audit_scoped.h	2011-08-19 23:22:48 +0000
+++ include/zorba/audit_scoped.h	2011-09-30 02:38:26 +0000
@@ -28,8 +28,10 @@
 
   class ZORBA_DLL_PUBLIC ScopedRecord {
   public:
-    ScopedRecord(Event* event) : theEvent(event), theRecord(0) {
-      assert(event);
+    ScopedRecord(Event* event)
+      : theEvent(event ? event : Event::get()),
+        theRecord(0) {
+      assert(theEvent);
     }
 
     ~ScopedRecord() {
@@ -104,6 +106,7 @@
   typedef ScopedAuditor<const int>               IntAuditor;
   typedef ScopedAuditor<zorba::time::Timer>      DurationAuditor;
   typedef ScopedAuditor<zorba::time::Timer, 0x1> TimestampAuditor;
+  typedef ScopedAuditor<zorba::time::Timer, 0x2> MicroDurationAuditor;
 
   template<> struct AuditorTraits<const std::string> {
     typedef const std::string value_type;
@@ -141,7 +144,7 @@
     static inline void start(value_type& value) {
     }
     static inline audit_type end(value_type& value) {
-      return value;
+      return static_cast<audit_type>(value);
     }
   };
 
@@ -189,6 +192,19 @@
       return static_cast<audit_type>(value.getStart());
     }
   };
+
+  template<> struct AuditorTraits<zorba::time::Timer, 0x2> {
+    typedef zorba::time::Timer value_type;
+    typedef long long          audit_type;
+    static inline void start(value_type& value) {
+      value.start();
+    }
+    static inline audit_type end(value_type& value) {
+      return static_cast<audit_type>(value.elapsed() * 1000);
+    }
+
+  };
+
 }
 }
 #endif

=== modified file 'src/api/auditimpl.cpp'
--- src/api/auditimpl.cpp	2011-08-19 23:22:48 +0000
+++ src/api/auditimpl.cpp	2011-09-30 02:38:26 +0000
@@ -395,6 +395,15 @@
 NOPEventImpl NOP_EVENT_IMPL;
 
 //************************************************************************
+// Event
+//************************************************************************
+
+Event*
+Event::get() {
+  return &NOP_EVENT_IMPL;
+}
+
+//************************************************************************
 // ProviderImpl
 //************************************************************************
 

=== modified file 'test/unit/test_audit.cpp'
--- test/unit/test_audit.cpp	2011-07-28 15:28:16 +0000
+++ test/unit/test_audit.cpp	2011-09-30 02:38:26 +0000
@@ -21,14 +21,12 @@
 #include <zorba/zorba.h>
 #include <zorba/store_manager.h>
 #include <zorba/audit.h>
+#include <zorba/audit_scoped.h>
 
-int
-test_audit(int argc, char* argv[])
+bool
+test_audit_1(zorba::Zorba* aZorba)
 {
-  void* store = zorba::StoreManager::getStore();
-  zorba::Zorba* lZorbaInstance = zorba::Zorba::getInstance(store);
-
-  zorba::audit::Provider* lAuditProvider = lZorbaInstance->getAuditProvider();
+  zorba::audit::Provider* lAuditProvider = aZorba->getAuditProvider();
   zorba::audit::Configuration* config = lAuditProvider->createConfiguration();
   std::vector<zorba::String> property_names;
   zorba::audit::Configuration::getPropertyNames(property_names);
@@ -52,8 +50,8 @@
 
   zorba::audit::Event* event = lAuditProvider->createEvent(config);
 
-  zorba::XQuery_t query = lZorbaInstance->createQuery();
-  zorba::StaticContext_t lStaticContext = lZorbaInstance->createStaticContext();
+  zorba::XQuery_t query = aZorba->createQuery();
+  zorba::StaticContext_t lStaticContext = aZorba->createStaticContext();
 
   lStaticContext->setAuditEvent(event);
 
@@ -64,7 +62,7 @@
   query->execute(std::cout, &lSerOptions);
 
   if (event->size() != 2) {
-    return 1;
+    return false;
   } else {
     // one record for the eval query and one for the main query
     const zorba::audit::Record* lRecord = event->at(0);
@@ -74,9 +72,47 @@
     std::cerr << *event << std::endl;
   }
 
-
-  lZorbaInstance->getAuditProvider()->submitEvent(event);
-  lZorbaInstance->getAuditProvider()->destroyConfiguration(config);
+  aZorba->getAuditProvider()->submitEvent(event);
+  aZorba->getAuditProvider()->destroyConfiguration(config);
+
+  return true;
+}
+
+bool
+test_audit_2(zorba::Zorba* aZorba)
+{
+  zorba::audit::Provider* lAuditProvider = aZorba->getAuditProvider();
+  zorba::audit::Configuration* config = lAuditProvider->createConfiguration();
+
+  {
+    // test to make sure that auditing doesn't crash if the record is initialized
+    // with a 0 event pointer
+    zorba::audit::ScopedRecord sar(0);
+    zorba::time::Timer lTimer;
+    zorba::audit::MicroDurationAuditor auditor(sar, "blub", lTimer);
+  }
+
+
+  aZorba->getAuditProvider()->destroyConfiguration(config);
+
+  return true;
+}
+
+int
+test_audit(int argc, char* argv[])
+{
+  void* store = zorba::StoreManager::getStore();
+  zorba::Zorba* lZorbaInstance = zorba::Zorba::getInstance(store);
+
+  if (!test_audit_1(lZorbaInstance))
+  {
+    return 1;
+  }
+
+  if (!test_audit_2(lZorbaInstance))
+  {
+    return 2;
+  }
 
   return 0;
 }

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to