blob: b52dde6779b16daa47d3083987b1848eadf99383 [file] [log] [blame]
/* -*- Mode: C++; tab-width: 4 indent-tabs-mode: nil -*-
*
* Copyright (c) 2015 Nest Labs, Inc.
* All rights reserved.
*
* This document is the property of Nest. It is considered
* confidential and proprietary information.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Nest.
*
* Description:
* This is the source file used to hook into gtest framework to
* send pinna shell command.
*
*/
#include "shell-command-nm.hpp"
#include "nluif.h"
void cmd_gtest_start(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
testing::UninitGoogleTest();
}
static int string_to_arg(char cmdline[], char *argv[]) {
int argc = 0;
char *c = NULL;
static char local_cmdline[256];
memcpy(local_cmdline, cmdline, strlen(cmdline) + 1);
c = strtok(local_cmdline, " ");
while (c && argc < UIF_NUM_CMD) {
argv[argc++] = c;
c = strtok(NULL, " ");
}
argv[argc] = NULL;
return argc;
}
void gtest_run_shell_cmd(char cmdline[])
{
/*
* Global array of pointers to emulate C argc,argv interface
*/
int argc;
char *argv[UIF_MAX_ARGS + 1]; /* one extra for null terminator */
argc = string_to_arg(cmdline, argv);
if (argc)
{
int i;
for (i = 0; i < UIF_NUM_CMD; i++)
{
if (strcasecmp(UIF_CMDTAB[i].cmd,argv[0]) == 0)
{
if (((argc-1) >= UIF_CMDTAB[i].min_args) &&
((argc-1) <= UIF_CMDTAB[i].max_args))
{
UIF_CMDTAB[i].func(argc,argv);
goto done;
}
else
{
goto done;
}
}
}
}
done:
return;
}
void gtest_nm_start() {
gtest_run_shell_cmd("nm start");
}
void gtest_nm_stop() {
gtest_run_shell_cmd("nm stop");
}