#!/bin/env perl

# This is a standalone testing executable for PS::MOPS::DC::Config.

use strict;

use Benchmark ':hireswallclock';

# Define variables for benchmarking.
our $g_START;
our $g_END;
our $g_DIFF;

# Testing environment.
use Test::More tests=>2; # Perl testing framework.
use PS::MOPS::DC::Config;
use PS::MOPS::Test::Instance;

my $test_inst=PS::MOPS::Test::Instance->new();
our $g_inst=$test_inst->getPSMOPSInstance();
our $g_dc_cfg; # Hold a config.
our $g_config_text; # Config text used to test the module.

# Test definition 1.
# Write a config file to the config table.
# Expected result: A config file is appended to the config table.
#
# @return {1|0} Success is 1, failure is 0.
sub test_modcfg_insert
{
    my $success=0;
    $g_config_text="This is test config text.";
    modcfg_insert($g_inst,$g_config_text);
    $g_dc_cfg=modcfg_retrieve($g_inst);
    if($g_dc_cfg eq $g_dc_cfg){ $success=1; }
    return $success;
}

# Test definition 2.
# Retrieve a configuration.
# Retrieve the latest one.
# Expected result: MOPS configuration.
#
# @return {1|0} Success is 1, failure is 0.
sub test_modcfg_retrieve
{
    my $success=0;
    $g_dc_cfg=modcfg_retrieve($g_inst); # Retrieve config text.
    if($g_dc_cfg eq $g_config_text ){ $success=1; }
    return $success;
}

# Perform test test_modcfg_insert.
$g_START=new Benchmark;
ok(test_modcfg_insert, "PS-MOPS-DC-Config->test_modcfg_insert");
$g_END=new Benchmark;
print "time: PS-MOPS-DC-Config->test_modcfg_insert: " . timestr(timediff($g_END,$g_START),'all') . "\n";

# Perform test test_modcfg_retrieve.
$g_START=new Benchmark;
ok(test_modcfg_retrieve, "PS-MOPS-DC-Config->test_modcfg_retrieve");
$g_END=new Benchmark;
print "time: PS-MOPS-DC-Config->test_modcfg_retrieve: " . timestr(timediff($g_END,$g_START),'all') . "\n";

