<commit_before>//  
// Copyright (C) 2008-2017 SIPez LLC.  All rights reserved.
//
//
// $$
///////////////////////////////////////////////////////////////////////////////

// Author: <NAME> <d<EMAIL> AT SIPez DOT com>
#include <os/OsIntTypes.h>
#include <sipxunittests.h>
#include <sipxunit/TestUtilities.h>

#include <os/OsFileSystem.h>
#include <os/OsFileInfoBase.h>
#include <os/OsFileBase.h>
#include <mp/MprRecorder.h>
#include <mp/MprnIntMsg.h>
#include <mp/MpGenericResourceTest.h>

MprRecorder::RecordFileFormat testFileTypes[] =
{
     MprRecorder::RAW_PCM_16,
     MprRecorder::WAV_PCM_16,
     MprRecorder::WAV_ALAW,
     MprRecorder::WAV_MULAW,
     MprRecorder::WAV_GSM
};

const char* testFileTypeStrings[] = 
{
     "RAW_PCM_16",
     "WAV_PCM_16",
     "WAV_ALAW",
     "WAV_MULAW",
     "WAV_GSM"
};
    
class MprRecorderTest : public MpGenericResourceTest
{
    CPPUNIT_TEST_SUITE(MprRecorderTest);
    CPPUNIT_TEST(testRecordToFile);
    CPPUNIT_TEST(testRecordToFileAppendNotExisting);
    CPPUNIT_TEST(testRecordToFileAppend);
    CPPUNIT_TEST(testRecordChannelToFileAppend);
    CPPUNIT_TEST(testRecordToPauseResumeFile);
    CPPUNIT_TEST_SUITE_END();

    void testRecordToFile()
    {<commit_msg>Added unit test for MprRecorder to test invalid file name<commit_after>//  
// Copyright (C) 2008-2018 SIPez LLC.  All rights reserved.
//
//
// $$
///////////////////////////////////////////////////////////////////////////////

// Author: <NAME> <dpetrie AT SIPez DOT com>
#include <os/OsIntTypes.h>
#include <sipxunittests.h>
#include <sipxunit/TestUtilities.h>

#include <os/OsFileSystem.h>
#include <os/OsFileInfoBase.h>
#include <os/OsFileBase.h>
#include <mp/MprRecorder.h>
#include <mp/MprnIntMsg.h>
#include <mp/MpGenericResourceTest.h>

MprRecorder::RecordFileFormat testFileTypes[] =
{
     MprRecorder::RAW_PCM_16,
     MprRecorder::WAV_PCM_16,
     MprRecorder::WAV_ALAW,
     MprRecorder::WAV_MULAW,
     MprRecorder::WAV_GSM
};

const char* testFileTypeStrings[] = 
{
     "RAW_PCM_16",
     "WAV_PCM_16",
     "WAV_ALAW",
     "WAV_MULAW",
     "WAV_GSM"
};
    
class MprRecorderTest : public MpGenericResourceTest
{
    CPPUNIT_TEST_SUITE(MprRecorderTest);
    CPPUNIT_TEST(testRecordToBadFile);
    CPPUNIT_TEST(testRecordToFile);
    CPPUNIT_TEST(testRecordToFileAppendNotExisting);
    CPPUNIT_TEST(testRecordToFileAppend);
    CPPUNIT_TEST(testRecordChannelToFileAppend);
    CPPUNIT_TEST(testRecordToPauseResumeFile);
    CPPUNIT_TEST_SUITE_END();

    void testRecordToBadFile()
    {
        UtlString recorderResourceName = "MprRecorder";
        MprRecorder* recorder = new MprRecorder(recorderResourceName);
        CPPUNIT_ASSERT(recorder);

        // Build flowgraph with source, MprRecorder and sink resources
        setupFramework(recorder);

        // Add the notifier so that we get resource events
        OsMsgQ resourceEventQueue;
        OsMsgDispatcher messageDispatcher(&resourceEventQueue);
        mpFlowGraph->setNotificationDispatcher(&messageDispatcher);

        // Start recording
        CPPUNIT_ASSERT_EQUAL(OS_FILE_ACCESS_DENIED,
                             MprRecorder::startFile(recorderResourceName,
                                                    *mpFlowGraph->getMsgQ(),
                                                    "bogus/file/path/ddd",
                                                    testFileTypes[0]));


        // Enable the source resource and the recorder
        CPPUNIT_ASSERT(mpSourceResource->enable());
        CPPUNIT_ASSERT(recorder->enable());

        OsStatus frameStatus = mpFlowGraph->processNextFrame();
        CPPUNIT_ASSERT_EQUAL(OS_SUCCESS, frameStatus);

        // Should be a failed to start message
        CPPUNIT_ASSERT_EQUAL(0, messageDispatcher.numMsgs());

        OsMsg* pMsg = NULL;
        while(messageDispatcher.numMsgs())
        {
            CPPUNIT_ASSERT_EQUAL(OS_SUCCESS, messageDispatcher.receive(pMsg, OsTime(0)));
            CPPUNIT_ASSERT(pMsg);
            MpResNotificationMsg* pNotif = (MpResNotificationMsg*) pMsg;

            switch(pNotif->getMsg())
            {
                default:
                    CPPUNIT_ASSERT(0);
                    printf("message type: %d from resource: %s\n",
                           pNotif->getMsg(),
                           pNotif->getOriginatingResourceName().data());
                    break;
            }
        }
    }

    void testRecordToFile()
    {
{'fraction_non_alphanumeric': 0.13532315978456014, 'fraction_numerical': 0.00807899461400359, 'mean_word_length': 2.4153256704980843, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3424178', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1385, 'n_words': 221}