

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/
//_/_/  This file is part of CMSDK version 2.1.1.260726 (26 July 2026)
//_/_/  
//_/_/  developed by
//_/_/  
//_/_/  Communicative Machines Ltd. 
//_/_/    http://cmlabs.com/
//_/_/  Copyright (c) 2026
//_/_/  
//_/_/  in collaboration with 
//_/_/  
//_/_/  Icelandic Institute for Intelligent Machines ses
//_/_/    Menntavegur 1
//_/_/    101 Reykjavik
//_/_/    ICELAND
//_/_/    http://www.iiim.is/
//_/_/
//_/_/  and is released under the following
//_/_/  
//_/_/  EXTENDED BSD License
//_/_/
//_/_/  Redistribution and use in source and binary forms, with or without
//_/_/  modification, is permitted provided that the following conditions 
//_/_/  are met:
//_/_/
//_/_/  - Redistributions of source code must retain the above copyright 
//_/_/    and collaboration notice, this list of conditions and the following 
//_/_/    disclaimer.
//_/_/
//_/_/  - Redistributions in binary form must reproduce the above copyright 
//_/_/    notice, this list of conditions and the following disclaimer in the 
//_/_/    documentation and/or other materials provided with the distribution.
//_/_/
//_/_/  - Neither the name of its copyright holders nor the names of its 
//_/_/    contributors may be used to endorse or promote products derived from 
//_/_/    this software without specific prior written permission.
//_/_/
//_/_/  - CADIA Clause: The license granted in and to the software under this 
//_/_/    agreement is a limited-use license. The software may not be used in 
//_/_/    furtherance of: (i) intentionally causing bodily injury or severe 
//_/_/    emotional harm to any person; (ii) invading the personal privacy or 
//_/_/    violating the human rights of any person; or (iii) committing or 
//_/_/    preparing for any act of war. 
//_/_/
//_/_/  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
//_/_/  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
//_/_/  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
//_/_/  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
//_/_/  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
//_/_/  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
//_/_/  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
//_/_/  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
//_/_/  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
//_/_/  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
//_/_/  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/*! @file UnitTest_CMSDK.cpp
    @brief Suite assembly for the CMSDK unit tests: collects each object's
           Register_*_Tests() function and implements the RunCMSDKTests()
           dispatch used by Psyclone's test= command line.
    @ingroup UnitTest */
#include "UnitTest_CMSDK.h"
#include "UnitTestFramework.h"
#include "ProcessMemory.h"   // for PerfTest_CMSDK back-compat entry

namespace cmlabs {

// ----------------------------------------------------------------------------
//  Per-object registration functions. Each is defined in its own object's .cpp
//  (where that object's header is cleanly included), and forward-declared here.
//  This avoids cross-header conflicts and keeps each test self-contained.
// ----------------------------------------------------------------------------
void Register_Utils_Tests();
void Register_PsyTime_Tests();
void Register_MessageIndex_Tests();
void Register_DataMessage_Tests();
void Register_Stats_Tests();
void Register_MovingAverage_Tests();
void Register_ThreadManager_Tests();
void Register_Subscriptions_Tests();

void Register_ComponentMemory_Tests();
void Register_MemoryManager_Tests();
void Register_ProcessMemory_Tests();
void Register_TemporalMemory_Tests();
void Register_MemoryRequestServer_Tests();
// NOTE: ComponentData, ControlMessage and MemoryQueues are NOT part of the CMSDK
// build (absent from the Makefile CPPFILES and unreferenced by any compiled
// code). Their unit tests exist in-source but are not registered here. Add the
// files to CPPFILES (resolving their header conflicts) to enable them.

void Register_RESTParser_Tests();
void Register_NetworkProtocols_Tests();
void Register_NetworkManager_Tests();
void Register_RequestGateway_Tests();
void Register_RequestClient_Tests();

void Register_Base64_Tests();
void Register_Hash_Tests();
void Register_MathClasses_Tests();
void Register_Bitmap_Tests();
void Register_HTML_Tests();
void Register_XMLParser_Tests();
void Register_VantagePoints_Tests();
void Register_Observations_Tests();

// ----------------------------------------------------------------------------
//  Central registration of every CMSDK unit test. Called once before running.
// ----------------------------------------------------------------------------
static bool g_registered = false;

void RegisterAllCMSDKTests() {
	if (g_registered) return;
	g_registered = true;

	// core / util
	Register_Utils_Tests();
	Register_PsyTime_Tests();
	Register_MessageIndex_Tests();
	Register_DataMessage_Tests();
	Register_Stats_Tests();
	Register_MovingAverage_Tests();
	Register_ThreadManager_Tests();
	Register_Subscriptions_Tests();

	// memory
	Register_ComponentMemory_Tests();
	Register_MemoryManager_Tests();
	Register_ProcessMemory_Tests();
	Register_TemporalMemory_Tests();
	// Registered but excluded from the default run (see note in the Register
	// function): MemoryRequestServer::init() fails on this platform. Available
	// to run by name (test=memoryrequestserver) for debugging.
	Register_MemoryRequestServer_Tests();

	// network / protocol
	Register_RESTParser_Tests();
	Register_NetworkProtocols_Tests();
	Register_NetworkManager_Tests();
	Register_RequestGateway_Tests();
	Register_RequestClient_Tests();

	// util / math / data
	Register_Base64_Tests();
	Register_Hash_Tests();
	Register_MathClasses_Tests();
	Register_Bitmap_Tests();
	Register_HTML_Tests();
	Register_XMLParser_Tests();
	Register_VantagePoints_Tests();
	Register_Observations_Tests();
}

// ----------------------------------------------------------------------------
//  Entry points
// ----------------------------------------------------------------------------
bool RunCMSDKTests(const char* name, const char* compareFile, const char* outFile,
                   const char* outDir, bool verbose, bool listOnly, bool forkPerTest) {
	RegisterAllCMSDKTests();
	UnitTestRunner& r = UnitTestRunner::instance();
	r.setVerbose(verbose);
	r.setForkPerTest(forkPerTest);
	if (compareFile) r.setCompareFile(compareFile);
	if (outFile)     r.setOutputFile(outFile);
	if (outDir)      r.setOutputDir(outDir);

	if (listOnly) { r.listTests(); return true; }

	if (name && *name && stricmp(name, "cmsdk") != 0 &&
	    stricmp(name, "sdk") != 0 && stricmp(name, "all") != 0)
		return r.runOne(name);

	return r.runAll();
}

bool IsCMSDKTest(const char* name) {
	RegisterAllCMSDKTests();
	return UnitTestRunner::instance().hasTest(name);
}

// Back-compatible entry (test=sdk). Runs all registered tests.
bool UnitTest_CMSDK() {
	return RunCMSDKTests(NULL, NULL, NULL, NULL, false, false, true);
}

bool PerfTest_CMSDK() {
	return ProcessMemory::PerfTest();
}

} // namespace cmlabs
