Permalink
Browse files

MockScorer and MockHitCollector

  • Loading branch information...
Veit Jahns
Veit Jahns committed Feb 7, 2011
1 parent 314b755 commit b04138e47ffb8239a0a069164bc159c876a103c5
Showing with 135 additions and 0 deletions.
  1. +2 −0 src/test/CMakeLists.txt
  2. +40 −0 src/test/search/MockHitCollector.h
  3. +93 −0 src/test/search/MockScorer.h
View
@@ -44,6 +44,8 @@ SET(test_files ./tests.cpp
./document/TestField.cpp
./store/TestStore.cpp
./store/MockRAMDirectory.cpp
+./search/MockScorer.h
+./search/MockHitCollector.h
./search/TestBoolean.cpp
./search/TestDateFilter.cpp
./search/TestForDuplicates.cpp
@@ -0,0 +1,40 @@
+/*------------------------------------------------------------------------------
+* Copyright (C) 2003-2011 Ben van Klinken and the CLucene Team
+*
+* Distributable under the terms of either the Apache License (Version 2.0) or
+* the GNU Lesser General Public License, as specified in the COPYING file.
+------------------------------------------------------------------------------*/
+
+#ifndef _lucene_search_MockHitCollector
+#define _lucene_search_MockHitCollector
+
+#include "CLucene/search/SearchHeader.h"
+
+CL_NS_DEF(search)
+
+class MockHitCollector : public HitCollector
+{
+public:
+
+ MockHitCollector() : HitCollector(), collectCalls(0) {}
+
+ virtual ~MockHitCollector() {}
+
+ virtual void collect(const int32_t doc, const float_t score)
+ {
+ collectCalls++;
+ }
+
+ int32_t getCollectCalls() const
+ {
+ return collectCalls;
+ }
+
+private:
+
+ int32_t collectCalls;
+};
+
+CL_NS_END
+
+#endif // _lucene_search_MockHitCollector
@@ -0,0 +1,93 @@
+/*------------------------------------------------------------------------------
+* Copyright (C) 2003-2011 Ben van Klinken and the CLucene Team
+*
+* Distributable under the terms of either the Apache License (Version 2.0) or
+* the GNU Lesser General Public License, as specified in the COPYING file.
+------------------------------------------------------------------------------*/
+
+#ifndef _lucene_search_MockScorer
+#define _lucene_search_MockScorer
+
+#include "CLucene/search/Scorer.h"
+
+CL_NS_DEF(search)
+
+class MockScorer : public Scorer
+{
+public:
+
+ MockScorer(Similarity* similarity) :
+ Scorer(similarity), nextCalls(0), skipToCalls(0), scoreHitCollectorCalls(0), scoreCalls(0)
+ {
+ /* empty */
+ }
+
+ virtual bool next()
+ {
+ nextCalls++;
+ return false;
+ }
+
+ virtual int32_t doc() const
+ {
+ return 0;
+ }
+
+ virtual bool skipTo(int32_t target)
+ {
+ skipToCalls++;
+ return true;
+ }
+
+ virtual Explanation* explain(int32_t doc)
+ {
+ return NULL;
+ }
+
+ virtual TCHAR* toString()
+ {
+ return NULL;
+ }
+
+ virtual float_t score()
+ {
+ scoreCalls++;
+ return 0;
+ }
+
+ virtual void score(HitCollector* hc)
+ {
+ scoreHitCollectorCalls++;
+ }
+
+ int32_t getNextCalls() const
+ {
+ return nextCalls;
+ }
+
+ int32_t getSkipToCalls() const
+ {
+ return skipToCalls;
+ }
+
+ int32_t getScoreCalls() const
+ {
+ return scoreCalls;
+ }
+
+ int32_t getScoreHitCollectorCalls() const
+ {
+ return scoreHitCollectorCalls;
+ }
+
+private:
+
+ int32_t nextCalls;
+ int32_t skipToCalls;
+ int32_t scoreHitCollectorCalls;
+ int32_t scoreCalls;
+};
+
+CL_NS_END
+
+#endif // _lucene_search_MockScorer

0 comments on commit b04138e

Please sign in to comment.