<commit_before>// Copyright (C) 2012-2016 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "IPCTestUtils.h"
#include <leapipc/IPCFileEndpoint.h>
#include <autowiring/autowiring.h>
#include <autowiring/CoreThread.h>
#include <cstdio>
#include <gtest/gtest.h>

using namespace leap::ipc;

class IPCFileEndpointTest :
  public testing::Test
{};

TEST_F(IPCFileEndpointTest, RawWriteToReadFromFile)
{
  std::string testMessage = "0123456789abcdef";
  const char* testFile = "IPCFileEndpoint_TestFile";

  // Write test message to file
  {
    std::shared_ptr<IPCFileEndpoint> ep = std::make_shared<IPCFileEndpoint>(testFile, false, true);
    ep->WriteRaw((void*)testMessage.c_str(), testMessage.size());
  }

  // Read test message from file
  {
    std::shared_ptr<IPCFileEndpoint> ep = std::make_shared<IPCFileEndpoint>(testFile, true, false);

    size_t bufsize = testMessage.size()+1;
    char* buf = new char[bufsize];
    buf[bufsize - 1] = 0;

    ep->ReadRaw((void*)buf, bufsize-1);

    ASSERT_EQ(strcmp(buf, testMessage.c_str()), 0);

    delete[] buf;
  }

  remove(testFile);
}<commit_msg>Add 2 channel test for File Endpoints<commit_after>// Copyright (C) 2012-2016 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "IPCTestUtils.h"
#include <leapipc/IPCFileEndpoint.h>
#include <autowiring/autowiring.h>
#include <autowiring/CoreThread.h>
#include <cstdio>
#include <gtest/gtest.h>

using namespace leap::ipc;

class IPCFileEndpointTest :
  public testing::Test
{};

TEST_F(IPCFileEndpointTest, RawWriteToReadFromFile)
{
  std::string testMessage = "0123456789abcdef";
  const char* testFile = "IPCFileEndpoint_TestFile";

  // Write test message to file
  {
    std::shared_ptr<IPCFileEndpoint> ep = std::make_shared<IPCFileEndpoint>(testFile, false, true);
    ep->WriteRaw((void*)testMessage.c_str(), testMessage.size());
  }

  // Read test message from file
  {
    std::shared_ptr<IPCFileEndpoint> ep = std::make_shared<IPCFileEndpoint>(testFile, true, false);

    size_t bufsize = testMessage.size()+1;
    char* buf = new char[bufsize];
    buf[bufsize - 1] = 0;

    ep->ReadRaw((void*)buf, bufsize-1);

    ASSERT_EQ(strcmp(buf, testMessage.c_str()), 0);

    delete[] buf;
  }

  remove(testFile);
}

TEST_F(IPCFileEndpointTest, FileEndpointTwoChannels)
{
  std::string testMessage1 = "0123456789abcdef";
  std::string testMessage2 = "fedcba9876543210";
  const char* testFile = "IPCFileEndpoint_TestFile2";

  // Write test messages to file
  {
    std::shared_ptr<IPCFileEndpoint> ep = std::make_shared<IPCFileEndpoint>(testFile, false, true);
    auto channel0 = ep->AcquireChannel(0, IPCEndpoint::Channel::WRITE_ONLY);
    auto channel1 = ep->AcquireChannel(1, IPCEndpoint::Channel::WRITE_ONLY);

    channel0->Write(testMessage1.c_str(), testMessage1.size());
    channel0->WriteMessageComplete();
    channel1->Write(testMessage2.c_str(), testMessage2.size());
    channel1->WriteMessageComplete();
  }

  // Read test messages from file
  {
    std::shared_ptr<IPCFileEndpoint> ep = std::make_shared<IPCFileEndpoint>(testFile, true, false);

    size_t bufsize = testMessage1.size() + 1;
    char* buf = new char[bufsize];
    buf[bufsize - 1] = 0;

    // read first message
    IPCEndpoint::Header hdr = ep->ReadMessageHeader();
    ASSERT_EQ(hdr.channel, 0);
    ASSERT_EQ(hdr.PayloadSize(), testMessage1.size());
    ep->ReadPayload(buf, hdr.PayloadSize());
    ASSERT_EQ(strcmp(buf, testMessage1.c_str()), 0);
    delete[] buf;

    hdr = ep->ReadMessageHeader(); // read empty EOM header
    ASSERT_EQ(hdr.eom, 1);

    bufsize = testMessage2.size() + 1;
    buf = new char[bufsize];
    buf[bufsize - 1] = 0;

    // read second message
    hdr = ep->ReadMessageHeader();
    ASSERT_EQ(hdr.channel, 1);
    ASSERT_EQ(hdr.PayloadSize(), testMessage2.size());
    ep->ReadPayload(buf, hdr.PayloadSize());
    ASSERT_EQ(strcmp(buf, testMessage2.c_str()), 0);
    delete[] buf;

    hdr = ep->ReadMessageHeader(); // read empty EOM header
    ASSERT_EQ(hdr.eom, 1);
  }

  remove(testFile);
}
{'fraction_non_alphanumeric': 0.14422840265813439, 'fraction_numerical': 0.024612355402412012, 'mean_word_length': 4.499323410013532, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7239026', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1395, 'n_words': 282}