<commit_before> /**
  * Copyright 2017 Comcast Cable Communications Management, LLC
  *
  * Licensed 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.
  *
 */
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <ctype.h>
#include <signal.h>

#include <CUnit/Basic.h>
#include <wrp-c/wrp-c.h>


#include "../src/schedule.h"
#include "../src/scheduler.h"
#include "../src/process_data.h"
#include "test_scheduler.h"

#include "scheduler_data0.h"
#include "scheduler_data1.h"
#include "scheduler_data2.h"
#include "scheduler_data3.h"
#define MAX_WRP_TEST_MSGS 4

static wrp_msg_t wrp_test_msgs[MAX_WRP_TEST_MSGS];    
static time_t kUnixCurrentTime = 1510689448;
static time_t add_time;

unsigned char *data_payloads[] = {
    scheduler_data0_bin,
    scheduler_data1_bin,
    scheduler_data2_bin,
    scheduler_data3_bin
};

#define TIME_SLOTS 5
uint32_t weekly_minute_offsets[MAX_WRP_TEST_MSGS][TIME_SLOTS] = {
    {10, 20, 30, 40, 35}, {10, 20, 30, 40, 50},
    {11, 23, 25, 43, 19}, {5, 11, 23, 37, 40}
};

pthread_t shceduler_thread_id;
const char *firewall_cmd = " ";
const char *file_name = "scheduler_data.bin";
const char *md5_file  = "md5.md5";

void initialize_wrp_messages(void);

/* Start the scheduler thread without any schedule data */
void test1()
{
    int result;
    result = scheduler_start( &shceduler_thread_id, firewall_cmd );
    CU_ASSERT(0 == result);
}


void test2()
{
    ssize_t result;
    int cnt;
    
    for (cnt = 0; cnt < MAX_WRP_TEST_MSGS; cnt++) {
        result = process_message_cu( file_name, md5_file, &wrp_test_msgs[cnt] );  
        CU_ASSERT(0 < result);
    }

    add_time = weekly_minute_offsets[0][0] * 60 * 5;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[0] );  
    CU_ASSERT(0 < result);

    add_time = weekly_minute_offsets[1][2] * 60 * 2;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[1] );  
    CU_ASSERT(0 < result);    

    add_time = weekly_minute_offsets[2][3] * 60;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[2] );  
    CU_ASSERT(0 < result);

    add_time = weekly_minute_offsets[3][1] * 60 * 3;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[3] );  
    CU_ASSERT(0 < result);
    
}


void add_suites( CU_pSuite *suite )
{
    printf("--------Start of Test Cases Execution For Scheduler---------\n");
    *suite = CU_add_suite( "tests", NULL, NULL );
    CU_add_test( *suite, "Scheduler Test 1", test1);
    CU_add_test( *suite, "Scheduler Test 2", test2);
}

/*----------------------------------------------------------------------------*/
/*                             External Functions                             */
/*----------------------------------------------------------------------------*/
int main( int argc, char *argv[] )
{
    unsigned rv = 1;
    CU_pSuite suite = NULL;
 <commit_msg>Use negative offsets for time (unix seconds on 11/14 11:57:28 AM was used in the JSON) so we can test weekly schedule<commit_after> /**
  * Copyright 2017 Comcast Cable Communications Management, LLC
  *
  * Licensed 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.
  *
 */
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <ctype.h>
#include <signal.h>

#include <CUnit/Basic.h>
#include <wrp-c/wrp-c.h>


#include "../src/schedule.h"
#include "../src/scheduler.h"
#include "../src/process_data.h"
#include "test_scheduler.h"

#include "scheduler_data0.h"
#include "scheduler_data1.h"
#include "scheduler_data2.h"
#include "scheduler_data3.h"
#define MAX_WRP_TEST_MSGS 4

static wrp_msg_t wrp_test_msgs[MAX_WRP_TEST_MSGS];
// Tuesday, November 14, 2017 11:57:28 AM PST = 1510689448
static time_t kUnixCurrentTime = 1510689448;
static time_t add_time;

unsigned char *data_payloads[] = {
    scheduler_data0_bin,
    scheduler_data1_bin,
    scheduler_data2_bin,
    scheduler_data3_bin
};

#define TIME_SLOTS 5
uint32_t weekly_minute_offsets[MAX_WRP_TEST_MSGS][TIME_SLOTS] = {
    {10, 20, 30, 40, 35}, {10, 20, 30, 40, 50},
    {11, 23, 25, 43, 19}, {5, 11, 23, 37, 40}
};

pthread_t shceduler_thread_id;
const char *firewall_cmd = " ";
const char *file_name = "scheduler_data.bin";
const char *md5_file  = "md5.md5";

void initialize_wrp_messages(void);

/* Start the scheduler thread without any schedule data */
void test1()
{
    int result;
    result = scheduler_start( &shceduler_thread_id, firewall_cmd );
    CU_ASSERT(0 == result);
}


void test2()
{
    ssize_t result;
    int cnt;
    
    for (cnt = 0; cnt < MAX_WRP_TEST_MSGS; cnt++) {
        result = process_message_cu( file_name, md5_file, &wrp_test_msgs[cnt] );  
        CU_ASSERT(0 < result);
    }

    add_time = -214980;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[0] );  
    CU_ASSERT(0 < result);

    add_time = -214500;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[1] );  
    CU_ASSERT(0 < result);    

    add_time = -213000;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[2] );  
    CU_ASSERT(0 < result);

    add_time = -212900;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[3] );
    CU_ASSERT(0 < result);

    add_time = 0; // allow absolute to take effect ?
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[3] );  
    CU_ASSERT(0 < result);
    
    add_time = -212790;
    result = process_message_cu( file_name, md5_file, &wrp_test_msgs[0] );
    CU_ASSERT(0 < result);
}


void add_suites( CU_pSuite *suite )
{
    printf("--------Start of Test Cases Execution For Scheduler---------\n");
    *suite = CU_add_suite( "tests", NULL, NULL );
    CU_add_test( *suite, "Scheduler Test 1", test1);
    CU_add_test( *suite, "Scheduler Test 2", test2);
}

/*----------------------------------------------------------------------------*/
/*                             External Functions                             */
/*----------------------------------------------------------------------------*/
int main( int argc, char *argv[] )
{
    unsigned rv = 1;
    CU_pSuite suite = NULL;
 
{'fraction_non_alphanumeric': 0.16146916146916146, 'fraction_numerical': 0.03853083853083853, 'mean_word_length': 2.875402792696026, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2228773', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2503, 'n_words': 653}