<commit_before>/*
** Copyright (C) 2006-2012 <NAME> <<EMAIL>>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "sfconfig.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <sndfile.hh>

#include "utils.h"

static short	sbuffer [100] ;
static int 		ibuffer [100] ;
static float	fbuffer [100] ;
static double	dbuffer [100] ;

static void
ceeplusplus_wchar_test (void)
{
#if 0
	LPCWSTR filename = L"wchar_test.wav" ;

	print_test_name (__func__, "ceeplusplus_wchar_test.wav") ;

	/* Use this scope to make sure the created file is closed. */
	{
		SndfileHandle file (filename, SFM_WRITE, SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 44100) ;

		if (file.refCount () != 1)
		{	printf ("\n\n%s %d : Error : Reference count (%d) should be 1.\n\n", __func__, __LINE__, file.refCount ()) ;
			exit (1) ;
			} ;

		/*	This should check that the file did in fact get created with a
		**	wchar_t * filename.
		*/
		exit_if_true (
			GetFileAttributesW (filename) == INVALID_FILE_ATTRIBUTES,
			"\n\nLine %d : GetFileAttributes failed.\n\n", __LINE__
			) ;
	}

	/* Use this because the file was created with CreateFileW. */
	DeleteFileW (filename) ;

	puts ("ok") ;
#endif
} /* ceeplusplus_wchar_test */



static void
create_file (const char * filename, int format)
{	SndfileHandle file ;

	if (file.refCount () != 0)
	{	printf ("\n\n%s %d : Error : Reference count (%d) should be zero.\n\n", __func__, __LINE__, file.refCount ()) ;
		exit (1) ;
		} ;

	file = SndfileHandle (filename, SFM_WRITE, format, 2, 48000) ;

	if (file.refCount () != 1)
	{	printf ("\n\n%s %d : Error : Reference count (%d) should be 1.\n\n", __func__, __LINE__, file.refCount ()) ;
		exit (1) ;
		} ;

	file.setString (SF_STR_TITLE, filename) ;

	/* Item write. */
	file.write (sbuffer, ARRAY_LEN (sbuffer)) ;
	file.write (ibuffer, ARRAY_LEN (ibuffer)) ;
	file.write (fbuffer, ARRAY_LEN (fbuffer)) ;
	file.write (dbuffer, ARRAY_LEN (dbuffer)) ;

	/* Frame write. */
	file.writef (sbuffer, ARRAY_LEN (sbuffer) / file.channels ()) ;
	file.writef (ibuffer, ARRAY_LEN (ibuffer) / file.channels ()) ;
	file.writef (fbuffer, ARRAY_LEN (fbuffer) / file.channels ()) ;
	file.writef (dbuffer, ARRAY_LEN (dbuffer) / file.channels ()) ;

	/* RAII takes care of the SndfileHandle. */
} /* create_file */

static void
check_title (const SndfileHandle & file, const char * filename)
{	const char *title = NULL ;

	title = file.getString (SF_STR_TITLE) ;

	if (title == NULL)
	{	printf ("\n\n%s %d : Error : No title.\n\n", __func__, __LINE__) ;<commit_msg>tests/cpp_test.cc: improve error reporting in check_title<commit_after>/*
** Copyright (C) 2006-2012 <NAME> <<EMAIL>>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "sfconfig.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <sndfile.hh>

#include "utils.h"

static short	sbuffer [100] ;
static int 		ibuffer [100] ;
static float	fbuffer [100] ;
static double	dbuffer [100] ;

static void
ceeplusplus_wchar_test (void)
{
#if 0
	LPCWSTR filename = L"wchar_test.wav" ;

	print_test_name (__func__, "ceeplusplus_wchar_test.wav") ;

	/* Use this scope to make sure the created file is closed. */
	{
		SndfileHandle file (filename, SFM_WRITE, SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 44100) ;

		if (file.refCount () != 1)
		{	printf ("\n\n%s %d : Error : Reference count (%d) should be 1.\n\n", __func__, __LINE__, file.refCount ()) ;
			exit (1) ;
			} ;

		/*	This should check that the file did in fact get created with a
		**	wchar_t * filename.
		*/
		exit_if_true (
			GetFileAttributesW (filename) == INVALID_FILE_ATTRIBUTES,
			"\n\nLine %d : GetFileAttributes failed.\n\n", __LINE__
			) ;
	}

	/* Use this because the file was created with CreateFileW. */
	DeleteFileW (filename) ;

	puts ("ok") ;
#endif
} /* ceeplusplus_wchar_test */



static void
create_file (const char * filename, int format)
{	SndfileHandle file ;

	if (file.refCount () != 0)
	{	printf ("\n\n%s %d : Error : Reference count (%d) should be zero.\n\n", __func__, __LINE__, file.refCount ()) ;
		exit (1) ;
		} ;

	file = SndfileHandle (filename, SFM_WRITE, format, 2, 48000) ;

	if (file.refCount () != 1)
	{	printf ("\n\n%s %d : Error : Reference count (%d) should be 1.\n\n", __func__, __LINE__, file.refCount ()) ;
		exit (1) ;
		} ;

	file.setString (SF_STR_TITLE, filename) ;

	/* Item write. */
	file.write (sbuffer, ARRAY_LEN (sbuffer)) ;
	file.write (ibuffer, ARRAY_LEN (ibuffer)) ;
	file.write (fbuffer, ARRAY_LEN (fbuffer)) ;
	file.write (dbuffer, ARRAY_LEN (dbuffer)) ;

	/* Frame write. */
	file.writef (sbuffer, ARRAY_LEN (sbuffer) / file.channels ()) ;
	file.writef (ibuffer, ARRAY_LEN (ibuffer) / file.channels ()) ;
	file.writef (fbuffer, ARRAY_LEN (fbuffer) / file.channels ()) ;
	file.writef (dbuffer, ARRAY_LEN (dbuffer) / file.channels ()) ;

	/* RAII takes care of the SndfileHandle. */
} /* create_file */

static void
check_title (const SndfileHandle & file, const char * filename)
{	const char *title = NULL ;

	title = file.getString (SF_STR_TITLE) ;

	if (title == NULL)
	{	printf ("\n\n%s %d : Error : No title for %s.\n\n", __func__, __LINE__, filename) ;
{'fraction_non_alphanumeric': 0.13418975390806376, 'fraction_numerical': 0.017953877108806686, 'mean_word_length': 3.8259895444361463, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3991198', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2229, 'n_words': 738}